1
votes

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.

1
Do you have anything logged to the console? Errors may be? Often times "things" appear to work correctly some times because the errors are often caused by data (meaning code not checking for nulls) etc.dynamicallyCRM
Sounds like a race condition. How did you register your onload function, through the menu or by code? If the latter is true, could you share this code here? Also, do you get the same unpredictable results in other browsers (Chrome, Firefox)?Henk van Boeijen

1 Answers

1
votes

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);