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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error creating record after update CRM Online 8.2 to 9.0

(0) ShareShare
ReportReport
Posted on by

Hello all, 

We recently updated one of our environment to version 9.0

Since then we have been getting "Bad request" when trying to create a record through javascript.

The exact same code works just fine on the environments we haven't updated. 

This is the object we are sending to create an incident record

entity = {
	casetypecode: 7,
	customerid_account@odata.bind:"/accounts(1AAF570D-A4E4-E711-80F7-3863BB344AC0)",
	subjectid@odata.bind: "/subjects(02b48911-69f3-e611-80f5-c4346bad92d0)",
	title: "Fourth Coffee (sample)"
}

This is the request

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/incidents", 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) {
            //Never gets here
        }
        else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send(JSON.stringify(entity));

Are there some modification that I have missed that need to be done for all request to get this working in this version ? 
Any help would be greatly appreciated

*This post is locked for comments

I have the same question (0)
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Jon,

    Can you try the below object-

    -----------------

    var entity = {};

    entity.casetypecode = 7;

    entity["customerid_account@odata.bind"] = "/accounts(1AAF570D-A4E4-E711-80F7-3863BB344AC0)";

    entity.title = "Fourth Coffee (sample)";

    entity["subjectid@odata.bind"] = "/subjects(02b48911-69f3-e611-80f5-c4346bad92d0)";

    -----------------

    Also, please ensure that you do have the casetypecode, account & subject passed in the above entity object

    Hope this helps.

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    You should also change your open statement to use v9.0 instead of 8.2 (api/data/v9.0/)

    Hope this helps

  • Verified answer
    NODAL Profile Picture
    860 on at

    Hi Jon,

    Also try " var globalContext=Xrm.Utility.getGlobalContext();

    globalContext.getClientUrl();" instead of Xrm.Page.context.getClientUrl()

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Jon,

    Try using the code below.

    var entity = {};
    entity.casetypecode = "7";
    entity["customerid_account@odata.bind"] = "/accounts(1AAF570D-A4E4-E711-80F7-3863BB344AC0)";
    entity["subjectid@odata.bind"] = "/subjects(02b48911-69f3-e611-80f5-c4346bad92d0)";
    entity.title = "Fourth Coffee (sample)";
    var req = new XMLHttpRequest();
    req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/incidents", 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 caseUri = this.getResponseHeader("OData-EntityId");
                console.log("Created case with URI: " + caseUri);
            }
            else {
                var error = JSON.parse(this.response).error;
                console.log(error.message);
            }
        }
    };
    req.send(JSON.stringify(entity));

    Hope this helps.

  • Verified answer
    Community Member Profile Picture
    on at

    It turns out that the request was okay all along.

    It was a error in a pre create plugin we have for that entity.

    Thank you very much for your help though

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans