CRM 2015 get lookup value

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);
            }
        }
    }
}

function getLookupGuid(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 

                return lookupRecordGuid;
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *