admin管理员组

文章数量:1423068

i can get the id of the contact but who i get the email of this contact ?????

function getdata(){
var entityName, entityId, entityLabel, lookupFieldObject;

    // parentaccountid is the lookup field name that we try to reach its values
    lookupFieldObject = Xrm.Page.data.entity.attributes.get('mbmhr_employee');
    if (lookupFieldObject.getValue() != null) {
        entityId = lookupFieldObject.getValue()[0].id;
        entityName = lookupFieldObject.getValue()[0].entityType;
        entityLabel = lookupFieldObject.getValue()[0].name;

Xrm.Page.getAttribute("mbmhr_test22").setValue(entityLabel );    

    }    
}

i can get the id of the contact but who i get the email of this contact ?????

function getdata(){
var entityName, entityId, entityLabel, lookupFieldObject;

    // parentaccountid is the lookup field name that we try to reach its values
    lookupFieldObject = Xrm.Page.data.entity.attributes.get('mbmhr_employee');
    if (lookupFieldObject.getValue() != null) {
        entityId = lookupFieldObject.getValue()[0].id;
        entityName = lookupFieldObject.getValue()[0].entityType;
        entityLabel = lookupFieldObject.getValue()[0].name;

Xrm.Page.getAttribute("mbmhr_test22").setValue(entityLabel );    

    }    
}
Share Improve this question edited Oct 27, 2015 at 13:29 ArK 21.1k67 gold badges111 silver badges136 bronze badges asked Oct 27, 2015 at 13:20 user5493786user5493786 411 gold badge1 silver badge3 bronze badges 1
  • 1 This is really really helpful! I was looking for that all day. The lookupFieldObject.getValue()[0].name will return the input value of the field upon validate and loss of focus! – scorpiophd Commented Oct 29, 2015 at 17:39
Add a ment  | 

2 Answers 2

Reset to default 1

You need to query the server for additional details of related records.

Have a look at Getting started with CRM 2011 JavaScript REST (OData) Web Service Calls and Retrieve Data using OData queries with Javascript in CRM 2013 to get you going in the right direction.

OData endpoint, once again, to the rescue:

var contactId = null;
try { contactId = Xrm.Page.getAttribute('mbmhr_employee').getValue()[0].id; } catch(ex) { contactId = null; }
if(contactId !== null)
{
    var req = new XMLHttpRequest();
    var url = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/ContactSet(guid'" + contactId + "')?$select=EMailAddress1";
    req.open("GET", url, true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function() {
        if(req.readyState == 4){
            var data = JSON.parse(req.responseText);
            // use data.d.EmailAddress1 
        }
    };
    req.send(null);
}

本文标签: get a value from lookup field in crm 2015 using javascriptStack Overflow