Cache Problem In D365 Portal / ADX Studio Portal.

Sometime we are facing the cache problem in D365 Portal / ADX Studio Portal. This kind of issue we faced when we updated anything directly within the CRM and changes not reflected within the Portal. To solve this issue, we have two ways:

First Way :
Go to CRM solution and click on the entity on which you facing this cache problem. Now go to "Change Tracking" option and enable this option as show in below snapshot. Portal use this feature to refresh the portal cache for a specific entity.


Second Way:
Step 1: Go to Poral and login with admin credential.

Step 2: Now navigate to the URL : <Portal URL>/_services/about

Step 3: Now click on Clear Cache button.

Retrieve the data using Odata Query in D365 Portal / ADX Studio Portal.

Hello Guys.....With the help of Odata Query we can retrieve the data in Portal from CRM and on the basis of this data we can apply some validation on it.
Here i will show you, How to retrieve the data from CASE entity using Odata query.

Before Moving forward, if you don't know, how to apply client side validation then click Here to know that.

Step 1: Go to Portal > Entity List. Create a new Entity List for Case Entity.



Step 2: Now scroll down this record and go to Odata Feed Section.
  • Click the Enabled Checkbox to enable the odata.
  • Give the Entity Type Name and Entity Set Name.
  • Select the view from which you want to retrieve the data or you can set your own custom view.

Step 3: Now, To retrieve the data, Hit the URL in browser.
  • URL : Portal_URL/_odata : This URL give the list of all entity set for which you have enabled the Odata.
  • URL : Portal_URL/_odata/Entity_Set_Name : This URL retrieve the data 



How to use odata to apply validation:

Here I applied validation on case like user not able to create case with same Title.  Check the below code and you can change this code as your requirement.


if (window.jQuery) {
   (function ($) {
      $(document).ready(function () {
         if (typeof (Page_Validators) == 'undefined') return;
         // Create new validator
         var newValidator = document.createElement('span');
         newValidator.style.display = "none";
         newValidator.id = "titleValidator";
         newValidator.controltovalidate = "title";
         newValidator.errormessage = "<a href='#title_label'>This Case has been already generated.</a>";
         newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
         newValidator.initialvalue = "";
         newValidator.evaluationfunction = function () {
       
var count =   GetCase();
            if (count > 0 ) 
              return false;   // Return false mean apply validation.
             else 
              return true;   // Return true mean successful.         
         };
         // Add the new validator to the page validators array:
         Page_Validators.push(newValidator);
         // Wire-up the click event handler of the validation summary link
         $("a[href='#title_label']").on("click", function () { scrollToAndFocus('title_label','title'); });
      });
   }(window.jQuery));
}

function GetCase(){
  var count = 0;
  var title=$("#title").val();

$.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: "~/_odata/Cases?$filter=title eq '"+title+"'",
    beforeSend: function(XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("Accept", "application/json");
    },
    async: false,
    success: function(data, textStatus, xhr) {
     count = data.value.length;        
    },
    error: function(xhr, textStatus, errorThrown) {
        Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
    }
  
});

return count;
}


Note: Refer the below link for complex Odata Query.
    https://msdn.microsoft.com/en-us/library/gg309461(v=crm.7).aspx



Click Here to know, Cache Problem In D365 Portal / ADX Studio Portal.

Apply Client Side validation in D365 Portal / ADX Studio Portal.

We have to use JS to apply client side validation in portal. Here i am making a field mandatory in Portal using JS but this field is not mandatory in CRM. This kind of requirement comes when a field is not mandatory in CRM but you have to make a field mandatory.

Step 1: Copy the below code and paste it in Notepad.


// Apply Client Side Validation on FieldName
if (window.jQuery) {
   (function ($) {
      $(document).ready(function () {
         if (typeof (Page_Validators) == 'undefined') return;
         // Create new validator
         var newValidator = document.createElement('span');
         newValidator.style.display = "none";
         newValidator.id = "FieldNameValidator";
         newValidator.controltovalidate = "FieldName";
         newValidator.errormessage = "<a href='#FieldName_label'>FieldName is required field.</a>";
         newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
         newValidator.initialvalue = "";
         newValidator.evaluationfunction = function () {
            var FieldName = $("#FieldName").val();       
if (FieldName == "")       
             return false;  // return false mean apply validation            
else 
             return true;   // return true mean successful         
         };
         // Add the new validator to the page validators array:
         Page_Validators.push(newValidator);
         // Wire-up the click event handler of the validation summary link
         $("a[href='#FieldName_label']").on("click", function () { scrollToAndFocus('FieldName_label','FieldName'); });
      });
   }(window.jQuery));
}

Step 2: Now modify this code as your requirement.
  • Here Replace the FieldName with your field name.
Step 3: Now apply this code on portal's page as show in below ScreenShot.




Now Check the Portal.

To apply the Asterisk (*) Sign using custom JS : 
 $('#FieldName_label').after('<span id="spanId" style="color: red;"> *</span>');  



Click Here to know, Retrieve the data using Odata Query in D365 Portal / ADX Studio Portal.