How To Populate Lookup Field Dynamically In Client Side
Solution 1:
Not sure from where you are getting the entity type code aka
objecttypecode
(10026), you may need to change the source to store entity type name (logical name). Since the object array used to store lookup value expects guid, display name & type like[{ id: recordid, name: recordName, entityType: entityName }]
. Otherwise like you commented you need to pull from Metadata or store some key:value pairs as enums.You can get all the needed properties from old field & set to new field like below.
-
var lookupObjValue = Xrm.Page.getAttribute(old_lookupSchemaName).getValue();
var lookupEntityType = lookupObjValue[0].entityType, //To get EntityName
lookupRecordGuid = lookupObjValue[0].id, // To get record GUID
lookupRecordName = lookupObjValue[0].name; //To get record Name
Xrm.Page.getAttribute(new_lookupSchemaName).setValue([{ id: lookupRecordGuid, name: lookupRecordName, entityType: lookupEntityType }]);
Solution 2:
If your requirement is no code (plugins) to me it seems a bit of a cheat to use JavaScript to achieve the same.
You should investigate how much of this could be done using a CRM Workflow, making a solution that would be supportable by a functional support person rather than a technical.
You could then optionally trigger the workflow using JavaScript
Post a Comment for "How To Populate Lookup Field Dynamically In Client Side"