Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

WEB API - Error with Custom Lookup to Custom Entity

Posted on by 1,540

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

  • RE: WEB API - Error with Custom Lookup to Custom Entity

    Thank you It works for me.

  • Ty8080 Profile Picture
    Ty8080 156 on at
    RE: WEB API - Error with Custom Lookup to Custom Entity

    Man, thank you for posting your solution. You just saved me from some frustration, had the same problem as you

  • Suggested answer
    Mamatha Raju Profile Picture
    Mamatha Raju 45 on at
    RE: WEB API - Error with Custom Lookup to Custom Entity

    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.

  • Suggested answer
    ISMAIL TUTUMLUER Profile Picture
    ISMAIL TUTUMLUER 399 on at
    RE: WEB API - Error with Custom Lookup to Custom Entity

    Thanks Chris. Capitalization worked for me. Need to pay attention to schema names

  • ChrisJC Profile Picture
    ChrisJC 1,540 on at
    RE: WEB API - Error with Custom Lookup to Custom Entity

    Hi Satish,

    I don't understand the question. It might be worth posting separately to get more exposure.

    Thanks,

    Chris

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: WEB API - Error with Custom Lookup to Custom Entity

    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..

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: WEB API - Error with Custom Lookup to Custom Entity

    Thanks ChrisJC, worked for me

  • Suggested answer
    Bangar Raju Profile Picture
    Bangar Raju 15 on at
    RE: WEB API - Error with Custom Lookup to Custom Entity

    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));

  • Verified answer
    ChrisJC Profile Picture
    ChrisJC 1,540 on at
    RE: WEB API - Error with Custom Lookup to Custom 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" />

  • M.T. Eikelenboom Profile Picture
    M.T. Eikelenboom 5,241 on at
    RE: WEB API - Error with Custom Lookup to Custom Entity

    How did you find out?

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