web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Creating new record using JAVA script WebAPI

(0) ShareShare
ReportReport
Posted on by 383

Hello all,

trying to create a new record using JS web API , it has lookup fields. I'm passing GUID like below, but it's throwing an error "BAD REQUEST".  i tried with commenting lookup fields, then it's working. Any help will be appreciated. Thank you in advance.

var entity = {};
entity.ca_agreementstartdate = new Date("02/11/2019").toISOString();
entity["ca_office@odata.bind"] = "/ca_offices(B61B0235-60AE-4EE3-BADE-21D96BB0F0B2)";

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/ca_preapprovalrequests", 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) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    There is known issue on 8.2 WebAPI, you need to use schema name for the lookup field instead of logical name

    entity["ca_office@odata.bind"] = "/ca_offices(B61B0235-60AE-4EE3-BADE-21D96BB0F0B2)";  //make sure to use schema name of the ca_office field instead of logical name

    More details here: [View:http://himbap.com/blog/?p=3103:320:50]

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans