web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

odata query

(0) ShareShare
ReportReport
Posted on by 2,215

Hi, I have a such a problem: in my code I want to retrieve customer's field text value (its type is a lookup).

function OnLoad() {

    var serverUrl = "http://" + window.location.host + "/" + Xrm.Page.context.getOrgUniqueName();

    var primarycontact = Xrm.Page.getAttribute("customerid").getValue();

    var primarycontactid = primarycontact[0].id;

    var primarycontacttype = primarycontact[0].entityType;

    alert(primarycontacttype);

 

 // Creating the Odata Endpoint

    var oDataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";

    var retrieveReq = new XMLHttpRequest();

    if (primarycontacttype == "contact") {

        var Odata = oDataPath + "/ContactSet?$select=new_ownershop_type&$filter=ContactId eq guid'" + primarycontactid + "'";

 

 

        retrieveReq.open("GET", Odata, false);

        retrieveReq.setRequestHeader("Accept", "application/json");

        retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");

        retrieveReq.onreadystatechange = function () { retrieveReqCallBack1(this); };

    }

   if (primarycontacttype == "account") {

        var Odata = oDataPath + "/AccountSet?$select=new_ownership_type&$filter=AccountId eq guid'" + primarycontactid + "'";

        retrieveReq.open("GET", Odata, false);

        retrieveReq.setRequestHeader("Accept", "application/json");

        retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");

        retrieveReq.onreadystatechange = function () { retrieveReqCallBack2(this); };

 

    }

    retrieveReq.send();

}

 

function retrieveReqCallBack1(retrieveReq) {

    if (retrieveReq.readyState == 4 /* complete */) {

        var retrieved = this.parent.JSON.parse(retrieveReq.responseText).d;

        var EmailAddress = retrieved.results[0].new_ownershop_type.Value;

 

        alert(EmailAddress.name);

    }

}

 

function retrieveReqCallBack2(retrieveReq) {

    if (retrieveReq.readyState == 4 /* complete */) {

        var retrieved = this.parent.JSON.parse(retrieveReq.responseText).d;

        var EmailAddress = retrieved.results[0].new_ownership_type.Value;

        alert(EmailAddress.name);

    }

}

 

 new_ownershop_type and new_ownership_type are lookup fields

Thanks!

 

*This post is locked for comments

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans