Get Lookup id / Text / EntityName in CRM using JavaScript

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”.

PhoneCall Webresource

Step 6: Open any phone call record. Select any record from To lookup field. You can see the below output.

PhoneCall Output

Please provide your valuable comments.

Set custom WhatsApp icon for custom Case Origin in CRM

In Case entity, for Origin field we can create custom icons to show them in Views, For instance you can see the below icons for Origin like Phone, Email and Web.

Case Home page grid Sample

Let us create a Custom Icon “WhatsApp”, and follow the below steps,

Step 1: Open Microsoft Dynamics CRM Online/On-Premise, and go to Settings -> Customizations. Click on Customizations.

Step 2: Go to Entities -> Case -> Fields. Open Origin OptionSet Field.

Origin Field in Case Entity

Step 3: Click on Edit and Create new Option and provide label as WhatsApp and Keep the default Value as 100000000.

WhatsApp Option Creation in Origin OptionSet

Step 4: Now our target is to show WhatsApp icon in view. So, create a new Web Resource of type PNG.

Before creating web resource, we should follow below points,

  1. Web Resource Name should start with prefix new.
  2. Name should be Incident_origincode_icon<WhatsApp OptionSet Value>.png.

In our example, WhatsApp OptionSet value is 100000000.

So our web Resource name is Incident_origincode_icon100000000.png

Click Here to download WhatsApp 16 X 16 PNG image.

After downloading, browse for the image in web resource. Save & Publish.

Incident Webresource

Step 5: Click on Create and click Case to create case record.

Quick Create Navigation

Provide the details and select Origin as “WhatsApp” and Save,

Case record Creation

Step 6: Finally Go to Microsoft Dynamics CRM -> Services -> Cases, to see list of cases in Home page grid

Output

I think you enjoyed of doing this activity. Please Comment on this post.

You can check main MSDN Article here.

Thanks.