Dynamics 365–Behavior when Lookup field is set in JavaScript

When you set value for Lookup attribute using JavaScript, with Dynamics 365 we have to take care of following issues which were not there in previous versions.

Problem: Problem is if any of the Lookup attribute  values are changed before Save then once the Save is completed it will trigger OnChange event of the Lookup attribute.

  • When setting id property make sure that GUID is enclosed in curly braces and its all UPPER Cases
    • Following code will cause OnChange event getting triggered
      var lookupItem = new Object();
      lookupItem.id = ‘{6976e322-1d82-e711-80ec-005056b80363}”;
    • Following code should work without any problem
      var lookupItem = new Object();
      lookupItem.id ='{6976E322-1D82-E711-80EC-005056B80363}’;
  • When setting entity logical name you could have used typename earlier without any problem however this property is no more supported and should be replaced by entityType
    • Following code must be avoided
      var lookupItem = new Object();
      lookupItem.typename = ‘new_protochildentity’;
    • Following is correct way to set entity logical name
      var lookupItem = new Object();
      lookupItem.entityType = ‘new_protochildentity’;
  • Also name property should also match exactly

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s