Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

Retrieve fields from related contact via JScript

$
0
0

Trying to retrieve some fields from the related contact record on a lead, but get the error "not defined at eval" can anyone tell me what i have wrong please?

function setContactFields() {

    //Get the contact lookup off of the record
    var contact = Xrm.Page.getAttribute('primarycontactid').getValue();

    //if contact exist, attempt to pull back the contact record
    if (contact != null && contact[0].entityType == "contact") {

        var contactId = contact[0].id;
        var serverUrl;

        if (Xrm.Page.context.getClientUrl !== undefined) {
            serverUrl = Xrm.Page.context.getClientUrl();
        }
        else {
            serverUrl = Xrm.Page.context.getServerUrl();
        }

        var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
        var contactRequest = new XMLHttpRequest();

        contactRequest.open("GET", ODataPath + "/ContactSet(guid'" + contactId + "')", false);
        contactRequest.setRequestHeader("Accept", "application/json");
        contactRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");

        contactRequest.send();

        //If request was successful, parse the associated contact account name

        if (contactRequest.status == 200) {

            var retrievedContact = JSON.parse(contactRequest.responseText).d;

            if (retrievedContact != null) {

                var retJobTitle = retrievedContact.jobtitle.getValue()

                Xrm.Page.getAttribute("jobtitle").setValue(retJobTitle);

            }
            else {
            }

        }
        else {
        }

    }
    else {
    }
}

Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images