Advertisements

Archive

Posts Tagged ‘Portals’

Dynamics Portals – Web Templates – ‘$ is not defined’ Error

Other day, I was getting ‘$ is not defined’ script error during my ‘Web Template’ load.

Portal_$_1

From the error, its clear that jQuery file reference was missing in Web Template.

The Web Template has a HTML with Liquid Template and script using jQuery and was rendering with no issues an hour ago and there were no changes made to the Web Template content.

Reason and Fix:

  • ‘Use Website Header and Footer’ field was unchecked in ‘Page Template’ which was causing the issue.

Portal_$_2

  • jQuery file would be implicitly available to the ‘Web Template’ when ‘Use Website Header and Footer’ field is checked on ‘Page Template’.
  • Save the Page Template
  • Clear the portal Cache and issue should be fixed.

🙂

 

 

 

Advertisements

[Code Snippet] Dynamics Portals/ADX – Set ‘Field Requirement’ using script

Below is the code snippet to set the requirement level (i.e., Required/Non-Required) of a field using script in portals. This logic handles all kind of field types including Check boxes.

Set Field As Required:

function SetFieldAsRequired(fieldName) {
if (typeof (Page_Validators) == ‘undefined’) return;
if ($(“#” + fieldName) != undefined && $(“#” + fieldName + “_label”) != undefined) {
$(“#” + fieldName).prop(‘required’, true);
$(“#” + fieldName).closest(“.control”).prev().addClass(“required”);

// Create new validator object
var Requiredvalidator = document.createElement(‘span’);
Requiredvalidator.style.display = “none”;
Requiredvalidator.id = fieldName + “Validator”;
Requiredvalidator.controltovalidate = fieldName;
Requiredvalidator.errormessage = “<a href=’#” + fieldName + “_label’>” + $(“#” + fieldName + “_label”).html() + ” is a required field.</a>”;
Requiredvalidator.initialvalue = “”;
Requiredvalidator.evaluationfunction = function () {
var fieldControl = $(“#” + fieldName);
if (fieldControl.is(“span”)) {
var value0 = $(“#” + fieldName + “_0”).prop(“checked”);
var value1 = $(“#” + fieldName + “_1”).prop(“checked”);
if (value0 == false && value1 == false) {
return false;
} else {
return true;
}
}
else {
var value = $(“#” + fieldName).val();
if (value == null || value == “”) {
return false;
} else {
return true;
}
}
};

// Add the new validator to the page validators array
Page_Validators.push(Requiredvalidator);
}
}

Set Field As Non Required:

function SetFieldAsNonRequired(fieldName) {
if (typeof (Page_Validators) == ‘undefined’) return;
if ($(“#” + fieldName) != undefined) {
$(“#” + fieldName).closest(“.control”).prev().removeClass(“required”);
$(“#” + fieldName).prop(‘required’, false);

for (i = 0; i < Page_Validators.length; i++) {
if (Page_Validators[i].id == fieldName + “Validator”) {
// Remove the current field’s ‘Required’ validator from ‘Page_Validators’ array
Page_Validators.splice(i);
}
}
}
}

How to use the functions:

  • Above functions can be called from ‘Custom JavaScript’ tab of Portal’s ‘Entity Form’.
  • Pass the Dynamics field’s schema name as the parameter to both functions.
    • In below example, ’emailaddress1′ is the field name which I want to set the Requirement level.

ADXJ_1

Refer the article for Portal script syntax’s and usage.

🙂

 

Dynamics Portals – ‘Record Mover’ and ‘Code Editor’ Tools – XrmToolBox

If you are a Dynamics Portal developer, couple of pain points you would have experienced, are

  • Moving configurations from environment to other
  • Navigating among multiple screens (Web Pages/Templates/Files etc…) to edit the configurations.

Lets see how these are addressed with below tools from our favorite XrmToolBox

  • Portal Records Mover
  • Portal Code Editor

Portal tools

Portal Records Mover:

To move the Portal configurations from environment to another, you might have used OOB “Configuration Migration Utility” tool but this tool has limitation as listed below.

  • You cannot choose records (For example, only specific Web Templates) as it would export all records for chosen entities.

With the ‘Portal Records Mover tool, now you can pick the sub set of records from Portal entities and you can apply Date filters and many more.

Usage steps:

  • From your XrmToolBox, connect to Portal Records Mover tool to your Dynamics instance.
  • Click on ‘Load Items’ , which load all Portal related entities.
  • From the “Options” tab,
    • Apply Date filters, if you want
    • Pick the ‘Web Site’, if you have multiple Portals (Custom Portal/Dealer Portal/etc..) installed

Export Records:

  • Choose the Portal Entities from left pane, you would like to migrate records from.
  • Click ‘Retrieve record’, to load the records from selected Portal entities.
  • Pick the records, you would like to migrate.

Portal Mover

  • Once you completed the record selection, click on “Export Records”
  • Choose the location to save the XML file.

Portal Mover - 2

  • XML file contain the records you selected.

Portal Mover - 3

Import Records:

  • To import the portal configuration to a Dynamics instance, you must have the XML prepared as mentioned above.
  • Click ‘Import records’ button and provide the portal configurations XML file.

Portal Mover - 4

Portal Code Editor:

This tool provides an easy way to edit all your Portal configurations in one place.

Note: This tool only works for Dynamics Portals and does not support ADX portals.

Usage steps:

  • Connect to Portal Code Editor tool to your Dynamics instance.
  • Click on ‘Load Items’ , which load all Portal related entities group by categories (i.e., Web Pages/Entity Forms/…).
  • Pick the record you want to update.
  • Modify the content and click ‘Save’ from ‘File’ menu.

Portal Code Editor

  • ‘Save’ just saves the content in Editor
  • To apply changes to your Dynamics instance, click on ‘Apply change to portal’ button

Portal Code Editor 2

Note:

  • Make sure you have the latest XrmToolBox downloaded, if you don’t find these tools.

Thanks to Tanguy TOUZARD for these amazing tools.

🙂