0
votes

I have Ribbon button on CustomEntity. CustomEntity has one text field and account lookup Based on the fields i'm Creating case Record. but record was not creating. could anybody help me on this? where i'm doing wrong. Below is my sample

function test() {
debugger;
var PostID = Xrm.Page.getAttribute("ism_name").getValue();
var ismaccount = Xrm.Page.getAttribute("ism_account").getValue()[0].name;
var serverUrl = document.location.protocol + "//" + document.location.host;
var incident = {};
incident.Title = PostID; 
incident.CustomerId = ismaccount;
var jsonEntity = window.JSON.stringify(incident);
//incident.Description = "Dynamicallty created record using REST Odata";
var oDataPath = serverUrl + "/Retail/XRMServices/2011/OrganizationData.svc"; 
var retrieveReq = new XMLHttpRequest(); 
var Odata = oDataPath + "/IncidentSet";
retrieveReq.open("POST", Odata, true);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");
retrieveReq.setRequestHeader("X-HTTP-Method", "CREATE");
retrieveReq.send(JSON.stringify(jsonEntity));
}
1

1 Answers

-1
votes

Can you give more information like the HTTP response? And what your version of OData? Is that V3 or V4? If it's V3, the request should look like

    POST serviceRoot/entityset HTTP/1.1

    DataServiceVersion: 3.0;
    MaxDataServiceVersion: 3.0;
    Content-Type: application/json;odata=minimalmetadata
    Accept: application/json;odata=minimalmetadata
    Accept-Charset: UTF-8

    {
      content of the entity
    }

If it's V4, the request should look like

    POST serviceRoot/EntitySet
    OData-Version: 4.0
    Content-Type: application/json;odata=minimalmetadata
    Accept: application/json
    {
       "@odata.type" : "namespace.type",
       content of the entity
    }

Seems that your code miss the odata version header.