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)

Web API Retrieve parent record look up filed value return bad request

(0) ShareShare
ReportReport
Posted on by

Hi,

I am trying to get the look up value from the parent record, based on the look up value I have to set the child record's fields.

The retrieve query works for text data from parent record, but gives bad request error when I try to get the parent record's look up field value.

In this example, it works fine if I just include $expand=new_FundRaiser($select=fullname)

but not when I add lookup_divisionid, any obvious error you can see?

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/new_fundraisings(46AA6C06-3652-E911-811A-005056919B9D)?$select=new_cardnameholder1&$expand=new_FundRaiser($select=fullname,lookup_divisionid)", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var new_cardnameholder1 = result["new_cardnameholder1"];
if (result.hasOwnProperty("new_FundRaiser")) {
var new_FundRaiser_fullname = result["new_FundRaiser"]["fullname"];
var new_FundRaiser_upbeat_divisionid = result["new_FundRaiser"]["lookup_divisionid"];
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Sreevalli Profile Picture
    3,256 on at

    Hi,

    For the lookup fields we have to use the name in a format "_fieldname_value"

    https://xyzcrm.api.crm4.dynamics.com/api/data/v9.1/leads(29c2d2f6-bd40-e911-a854-000d3ab0dc71)?$select=_parentaccountid_value

  • Community Member Profile Picture
    on at

    Hi,

    The "_fieldname_value" format works for the look up values in the same entity, when I try to do the same with the lookup value of the parent record it fails as before

    $select=new_cardnameholder1,_new_fundraisingevent_value&$expand=new_FundRaiser($select=contactid,fullname,_lookup_divisionid_value)"

    When I add  _new_funraisingevent_value it works but freezes when I add _lookup_divisionid_value

  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at

    Hi Rummy,

    Could you share the error, I tried and it worked

    my Request :

    xxxxxxxxxxxxxxxxxxxx.api.crm4.dynamics.com/.../incidents(7E392284-0856-E911-A849-000D3AB0D976)$select=title,_customerid_value&$expand=customerid_contact($select=fullname,_parentcustomerid_value)

    Given Response:

    {"@odata.context":"xxxxxxxxxxxxxxxxxxxx.api.crm4.dynamics.com/.../v9.1/$metadata#incidents(title,_customerid_value,customerid_contact(fullname,_parentcustomerid_value))/$entity","@odata.etag":"W/\"6124687\"","title":"2132132312","_customerid_value":"bb7f72e1-543b-e911-a841-000d3ab1da01","incidentid":"7e392284-0856-e911-a849-000d3ab0d976","customerid_contact":{"@odata.etag":"W/\"4354842\"","fullname":"XXX XXXX","_parentcustomerid_value":"714c9cb7-9b3a-e911-a841-000d3ab1da01","contactid":"bb7f72e1-543b-e911-a841-000d3ab1da01"}}

  • Community Member Profile Picture
    on at

    You are right, I was in the Jlattimer REST building app and think it's the builder that froze, when I tried the URL it works like a charm.

    Thank you Sreevalli!

  • Community Member Profile Picture
    on at

    Can I ask how do you read the request.send() for a particular element like division in my example from a javascript? Any link to the topic will be helpful , when I search for Jason request read I get all c# coding results!

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