Posted By

chetkloss on 02/21/13


Tagged

lookup crm Dynamics


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

chetkloss


Dynamics CRM - Get or Set Values Lookup Field Values


 / Published in: JavaScript
 

Code returns text value of lookup field

  1. if (typeof (CLKLookup) == "undefined")
  2. { CLKLookup = { __namespace: true }}
  3.  
  4. CLKLookup.Utility = {
  5.     GetSetLookup: function () {
  6.         //Get a lookup value     
  7.         var lookupItem = new Array();
  8.         lookupItem = Xrm.Page.getAttribute("yourAttributeSchemaName").getValue();
  9.         if (lookupItem[0] != null) {
  10.             var name = lookupItem[0].name;
  11.             var guid = lookupItem[0].id;
  12.             var entType = lookupItem[0].entityType;
  13.         }
  14.  
  15.         //Set a lookup value    
  16.         var value = new Array();
  17.         value[0] = new Object();
  18.         value[0].id = idValue;
  19.         value[0].name = textValue;
  20.         value[0].entityType = typeValue;
  21.         Xrm.Page.getAttribute("yourAttributeSchemaName").setValue(value);
  22.  
  23.         //or alternatively you can set it like this   
  24.         Xrm.Page.getAttribute("yourAttributeSchemaName").setValue( [{id: idValue, name: textValue, entityType: typeValue}]);
  25.     },
  26.  
  27.     __namespace: true
  28. };

Report this snippet  

You need to login to post a comment.