Get Lookup id / Text / EntityName in CRM using JavaScript

Arun Potti's MS CRM blog

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…

View original post 96 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s