Get and Set Look Up Details in CRM 2011/2013/2015.

Hi,

Here is the JavaScript for getting/setting Look Up details in CRM 2011/2013/2015.

// Get Look Up Details.

function getLookUp() {
    var varEntityName, varEntityId, varEntityType, varLookupFieldObject;
    var varLookupFieldObject = Xrm.Page.data.entity.attributes.get(“parentaccountid”);
    // Get Parent Account Details.
    if (varLookupFieldObject.getValue() != null) {
        varEntityId = varLookupFieldObject.getValue()[0].id;
        varEntityType = varLookupFieldObject.getValue()[0].entityType;
        varEntityName = varLookupFieldObject.getValue()[0].name;
        setLookUpValue(varEntityId, varEntityName, varEntityType)
    }
}

// Set the Look Up.
function setLookUpValue(accountId, accountName, entityLogicalName) {
    Xrm.Page.getAttribute(“new_populateparentaccount”).setValue([{
        id: accountId,
        name: accountName,
        entityType: entityLogicalName
    }]);
}

Hope this helps.


Happy CRM’ing
Gopinath.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s