Sunday 25 June 2017

Get Lookup id / Text / EntityName in CRM using JavaScript in Dynamic CRM.

Get Lookup id / Text / EntityName in CRM using JavaScript in Dynamic CRM.
Description:
In this example we explain that how to get Lookup ID/Text/Entity name in Dynamic CRM using JavaScript. Or how to get the details of the Lookup Id and Name using JavaScript in Dynamic CRM.

Suppose you have Lead form in which we have one Account Lookup so after change of the Lookup suppose we have to get the Details of the Account that we are selected so below is the code to get or retrieve the Id and Name of the Lookup that we have selected.
Javascript 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);
      }
   }
  }
}


0 comments:

Post a Comment