Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

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

Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web API Retrieve parent record look up filed value return bad request

    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!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web API Retrieve parent record look up filed value return bad request

    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!

  • Suggested answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Web API Retrieve parent record look up filed value return bad request

    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
    Community Member Microsoft Employee on at
    RE: Web API Retrieve parent record look up filed value return bad request

    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

  • Verified answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Web API Retrieve parent record look up filed value return bad request

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans