JavaScript to get the lookup object and lookup attributes in MSCRM/D365.

Spread the Knowledge...

This method can be used to retrieve the lookup object along with its ID, Name and EntityType.

function GetLookupDetails() { 
var fieldSchemaName = "accountid"; //Lookup Schema name 
var lookupObject = Xrm.Page.getAttribute(fieldSchemaName); //get the Lookup Object 
if (lookupObject != null) { 
var lookupObjectValues = lookupObject.getValue();//get the Lookup Value 
if (lookupObjectValues != null) 
{ 
lookupObjRecordid = lookupObjectValues[0].id; //get the Lookup id 
lookupObjRecordName = lookupObjectValues[0].name; //get the Lookup Name 
lookupObjEntityType = lookupObjectValues[0].entityType; //get the Lookup EntityName 
} 
} 
}

Hope this helps…


Spread the Knowledge...