Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

400 error: While creating record through web api using javascript

Posted on by 520

Hi Experts,

I'm facing 400 error while creating a custom entity record using CRM web API.

The problem is passing data for lookup fields. tried changing different formats of json object for lookups, but no luck.

Format 1:

entity.primarycontactid = {
            Id: "ba121cbc-6a41-e611-80e0-c4346bc58294",
            LogicalName: "contact"
        };

Format 2:

var entity = {};

entity["account@odata.bind"] = "/accounts("ba121cbc-6a41-e611-80e0-c4346bc58294")";

entity["pricelist@odata.bind"] = "/pricelevels("ba121cbc-6a41-e611-80e0-c4346bc58294")";

Other fields works fine.

Any help is much appreciated.

*This post is locked for comments

  • Verified answer
    sardar ahmed Profile Picture
    sardar ahmed 520 on at
    RE: 400 error: While creating record through web api using javascript

    Thanks for the help guys!

    I have resolved the issue, it was that, i need to give schema name(pre_Account) for fields rather than logical name(pre_account).

    Thanks and Regards

    Sardar Ahmed.

  • Suggested answer
    RE: 400 error: While creating record through web api using javascript

    Hi Sardar, There are times when the REST builder also will fail especially for Custom entity lookups. Download Odata Metadata (Developer Resources) and copy the exact attribute name from that .

    Thanks.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: 400 error: While creating record through web api using javascript

    Hi Sardar,

    Its easy to create your code using RestBuilder , just download it and import the solution. You will find a button like ribbon work bench in solution area .

    Click on the CRM  rest builder button and select your entity , attributes and click on create request. This will give you the auto generate code.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: 400 error: While creating record through web api using javascript

    Hello,

    Try CRMRestBuilder to build queries - github.com/.../2.5.0.0

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans