Hi,
I'm trying to use the new web api to import a record. I have the details in json file. When I exclude the lookup field the record goes in fine.
When I include the lookup field I get a 400 error: Bad Request.
I've tried multiple ways to format this and believe this is the correct way:
"wt_propertyid@odata.bind": "mycrm.crm4.dynamics.com/.../wt_properties(31095689-ACDC-E611-8110-3863BB355D40)"
or
"wt_propertyid@odata.bind": "/wt_properties(31095689-ACDC-E611-8110-3863BB355D40)"
The details are:
Parent Entity (Property) wt_property
Child Entity (Space) wt_space
Lookup to Parent wt_property
I have tried with and without the id in the field name (before the '@')
*This post is locked for comments
Thank you It works for me.
Man, thank you for posting your solution. You just saved me from some frustration, had the same problem as you
Hi Chris,
Thanks for the above post. It worked when we tried to pass as below.
"wt_propertyid@odata.bind": "mycrm.crm4.dynamics.com/.../wt_properties(31095689-ACDC-E611-8110-3863BB355D40)"
Thanks & Regards,
Mamatha Raju Babu.
Thanks Chris. Capitalization worked for me. Need to pay attention to schema names
Hi Satish,
I don't understand the question. It might be worth posting separately to get more exposure.
Thanks,
Chris
Hi,
Schema Name is required that's correct but what if the when we update/create the activity type record having custom lookup attribute if any other entity.
Highly appreciated for any potential input.
Thanks..
Thanks ChrisJC, worked for me
While creating CRM record using Web Api we need to use Odata CRM Schema Names not name of the attribute.
ie, if the field is created with name "new_accountname" then the Schema name is looks like "new_AccountName".
So While setting lookup value we need to follow the below syntax instead of using auto code generated by CRMRestBuilder.
Ex:
var entity = {};
entity["new_AccountName@odata.bind"] ="/contacts(89153C7D-E45E-E611-80F6-1458D05A5490)"
var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts(bf121cbc-6a41-e611-80e0-c4346bc58294)", 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.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
//Success - No Return Data - Do Something
}
else {
alert(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
I saw another query where the response was try capitals. Then through trial and error found that was the correct version.
Then, by going to customisations -> developer resources and clicking the OData Metada doc I found on the navigation property for that relations, the Partner is capitalised which I assume is what the API is using rather than the field directly:
<NavigationProperty Name="wt_wt_property_wt_space_Property" Type="Collection(mscrm.wt_space)" Partner="wt_Property" />
How did you find out?
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,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156