Hi Experts,
Is is possible with single web api call to fetch the record along with its child record.
i.e I have to fetch the quote record and its associated quote product records in single web api call.
Hi Experts,
Is is possible with single web api call to fetch the record along with its child record.
i.e I have to fetch the quote record and its associated quote product records in single web api call.
Thanks Clofly
Hi Ahtesham,
Yes, it is possible to do it if relationship between parent record and its children record is 1:N.
As for your example, due to quote <-> products(quote lines) is 1:N, so you can retrieve associated product records of a quote by $expand query.
Steps:
1. Find relationship name in Customization:
2. Excute web api with expression:
$expand=quote_details($select=xx1,xx2)
Result:
some fields of parent quote:
associated products:
execute web api directly in address bar:
javascript code which is generated by CRMRestBuilder:
var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() "/api/data/v9.1/quotes(5db5d46b-a577-ea11-a811-000d3af421db)?$select=name,_pricelevelid_value,quoteid,quotenumber,_transactioncurrencyid_value&$expand=quote_details($select=extendedamount,priceperunit,productname,quantity)", 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 name = result["name"]; var _pricelevelid_value = result["_pricelevelid_value"]; var _pricelevelid_value_formatted = result["_pricelevelid_value@OData.Community.Display.V1.FormattedValue"]; var _pricelevelid_value_lookuplogicalname = result["_pricelevelid_value@Microsoft.Dynamics.CRM.lookuplogicalname"]; var quoteid = result["quoteid"]; var quotenumber = result["quotenumber"]; var _transactioncurrencyid_value = result["_transactioncurrencyid_value"]; var _transactioncurrencyid_value_formatted = result["_transactioncurrencyid_value@OData.Community.Display.V1.FormattedValue"]; var _transactioncurrencyid_value_lookuplogicalname = result["_transactioncurrencyid_value@Microsoft.Dynamics.CRM.lookuplogicalname"]; for (var a = 0; a < result.quote_details.length; a ) { var quote_details_extendedamount = result.quote_details[a]["extendedamount"]; var quote_details_extendedamount_formatted = result.quote_details[a]["extendedamount@OData.Community.Display.V1.FormattedValue"]; var quote_details_priceperunit = result.quote_details[a]["priceperunit"]; var quote_details_priceperunit_formatted = result.quote_details[a]["priceperunit@OData.Community.Display.V1.FormattedValue"]; var quote_details_productname = result.quote_details[a]["productname"]; var quote_details_quantity = result.quote_details[a]["quantity"]; var quote_details_quantity_formatted = result.quote_details[a]["quantity@OData.Community.Display.V1.FormattedValue"]; } } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send();
Regards,
Clofly
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156