It is required sometimes to get Lookup Id / Text / Entity schema name of the selected record from Lookup. To get that follow the below task.
Task: Get record GUID, record Name and Entity Type from the Phone Call entity OnChange of To field.
Solution: Please follow the below steps,
Step 1: Create a web resource of type Jscript and name it as “new_phonecall”.
Step 2: Click on Text Editor, copy paste the below code.
function toOnChange(){ getLookupDetails("to"); } function getLookupDetails(lookupSchemaName) { var lookupObj = Xrm.Page.getAttribute(lookupSchemaName); //Check for Lookup Object if (lookupObj != null) { var lookupObjValue = lookupObj.getValue();//Check for Lookup Value if (lookupObjValue != null) { var lookupEntityType = lookupObjValue[0].entityType, //To get EntityName lookupRecordGuid = lookupObjValue[0].id, // To get record GUID lookupRecordName = lookupObjValue[0].name; //To get record Name if (lookupEntityType != null && lookupRecordGuid != null && lookupRecordName != null) { Xrm.Utility.alertDialog("Entity Type : " + lookupEntityType + "\nRecord GUID : " + lookupRecordGuid + "\nRecord Name : " + lookupRecordName, null); } } } }
Step 3: Save & Publish Jscript web resource.
Step 4: Open phonecall form click on Form Properties, and attach Jscript Library “new_phonecall” to Form Libraries.
Step 5: Select Control “To” and Event “OnChange”. Select “new_phonecall” library and provide function name “toOnChange”.
Step 6: Open any phone call record. Select any record from To lookup field. You can see the below output.
Please provide your valuable comments.
Discover more from Arun Potti's Power Platform blog
Subscribe to get the latest posts to your email.
Thanks Arun. Great article.
Reblogged this on sabihahmedkhanblog.
This nolonger works for CRM 2015 Online Update 1. the lookupObj.getValue() function returns an empty object [].
Does someone know a fix?
Hi Cooler,
I have tested the same code in CRM 2015 with Update 1, 30 days trial version. It is working fine.
Please check the Schema Name of the Lookup.
Thanks Arun.