Set Lookup Value using JavaScript in MSCRM

Syntax:

Name Type Description
lookUpSchemaName String The lookup attribute logical name
entitySchemaName String The logical name of the entity being set.
recordId String A string representation of the GUID value for the record being set.
The expected format is “{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}”.
recordName String The text to be displayed in the lookup.
function setLookupValue(lookUpSchemaName, entitySchemaName, recordId, recordName) {
    var lookUpObj = [];
    lookUpObj[0] = {};
    lookUpObj[0].id = recordId;
    lookUpObj[0].entityType = entitySchemaName;
    lookUpObj[0].name = recordName;
    if (Xrm.Page.getAttribute(lookUpSchemaName) != null)
        Xrm.Page.getAttribute(lookUpSchemaName).setValue(lookUpObj);
}

Alternate Method

function setLookupValue(lookUpSchemaName, entitySchemaName, recordId, recordName) {
    Xrm.Page.getAttribute(lookUpSchemaName).setValue([{
        entityType: entitySchemaName,
        id: recordId,
        name: recordName
    }]);
}

Please provide your valuable comments on this article.

Advertisement

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.