Showing posts with label Access Lookup value in javascript. Show all posts
Showing posts with label Access Lookup value in javascript. Show all posts

Saturday, October 23, 2021

Get Lookup Value in MS CRM 365 using JavaScript

 

While working on client-side customization using Java Script in MS CRM 365, it is very common requirement to get the Lookup field value which can be done using following code-

Let’s look into the code step by step-

First of all we have to get the entity object using formContext.data.entity.attributes.get() Method

E.g.

var ObjAccount = formContext.data.entity.attributes.get("accountid");  

 

Once the object is available in the variable ObjAccount we can use GetValue() method as shown below-

E.g.

var ObjAccountValues = ObjAccount.getValue();

 

GetValue() Metho return the id, name and entityType properties which can we accessed as shown in full function written to get the Looup Values

function LookupValueFctn(executionContext) {
    var formContext = executionContext.getFormContext();
var ObjAccount=formContext.data.entity.attributes.get("accountid");  

    if (ObjAccount != null) {
        var ObjAccountValues = ObjAccount.getValue();

        if (ObjAccountValues != null) {
            var Accountid = ObjAccountValues[0].id;  
            var AccountNameName = ObjAccountValues[0].name;
            var EntitySchemaName =ObjAccountValues[0].entityType;
        }
    }
}

 

QueryExpression vs. FetchXML in MS CRM with C#

Microsoft Dynamics CRM (Customer Relationship Management) is a powerful platform that helps organizations streamline their business processe...