Search code examples
dynamics-crmdynamics-crm-onlinedynamics-crm-2015dynamics-crm-2016xrm

Issues in some javascripts after upgrading to Dynamics CRM Online 2016


We have just upgraded one of our Dynamics CRM instance from CRM Online 2015 to CRM Online 2016.

While I could see rest of the functionalities working properly, there is a major show stopper for us in a particular scenario:

Following is the code from a java script function which gets called during page load:

function SetDefaultValuesInLookup()
{
  Xrm.Page.getAttribute("new_applicationcontactid").setValue([{ id: 
records.new_Contact.Id, name: records.new_Contact.Name, entityType: records.new_Contact.LogicalName }]);

  ........

  Xrm.Page.getAttribute("new_applicationtype").setValue(1000002);
}

function ShowHideFields()
{
  var applicationtype = Xrm.Page.getAttribute("new_applicationtype").getValue();

  ...............

}

To summarize SetDefaultValuesInLookup function sets a value for the lookup field "Application Contact Id" in the form, and also sets "new_applicationtype" based on some condition.

This two functions are registered in the form load to get executed in an order. however, the problem is that - sometimes the method SetDefaultValuesInLookup abruptly terminates after executing first getAttribute value, or if the method completes its execution, then we don't get value in new_applicationtype field. Or sometimes, both the method works properly.

I tried debugging the code, and could see we are getting Id, Name, and LogicalName properties are getting populated everytime, so there is no issue at that level.

I am wondering if there is something here which is not supported in CRM 2016? Also, this functionality still perfectly works in Online 2015.


Solution

  • Try with below given code, it worked for me

    var object = new Array();
    		object[0] = new Object();
    		object[0].id = records.new_Contact.Id;
    		object[0].name = records.new_Contact.Name;
    		object[0].entityType = records.new_Contact.LogicalName;
    		Xrm.Page.getAttribute(fieldName).setValue(object);