/ Published in: JavaScript
Code returns text value of lookup field
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
if (typeof (CLKLookup) == "undefined") { CLKLookup = { __namespace: true }; } CLKLookup.Utility = {     GetSetLookup: function () {         //Get a lookup value             var lookupItem = new Array();         lookupItem = Xrm.Page.getAttribute("yourAttributeSchemaName").getValue();         if (lookupItem[0] != null) {             var name = lookupItem[0].name;             var guid = lookupItem[0].id;             var entType = lookupItem[0].entityType;         }         //Set a lookup value            var value = new Array();         value[0] = new Object();         value[0].id = idValue;         value[0].name = textValue;         value[0].entityType = typeValue;         Xrm.Page.getAttribute("yourAttributeSchemaName").setValue(value);         //or alternatively you can set it like this           Xrm.Page.getAttribute("yourAttributeSchemaName").setValue( [{id: idValue, name: textValue, entityType: typeValue}]);     },     __namespace: true };