Use /XRMServices/2011/OrganizationData.svc
Folks,
I have been using CRM Online/2016 and when I have tried CRUD oData in JS, /XRMServices/2011/Organization.SVC didn't work....browser was throwing strange errors on content type. But actually the reason was to use /XRMServices/2011/OrganizationData.svc INSTEAD of wrong links given in the developer resources.
So the sample code for update record could be like below
function updateRecord (id, object, type) {
var context = GetGlobalContext();
var serverUrl = context.getClientUrl();
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc/";
var req = new XMLHttpRequest();
req.open("POST", encodeURI(serverUrl + ODATA_ENDPOINT + type + "(guid'" + id + "')"), false);
req.setRequestHeader("Cache-Control", "no-cache");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("X-HTTP-Method", "MERGE");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 204 || this.status == 1223) {
// successCallback();
alert("SUCCESS");
}
else {
alert("FAILED");
}
}
};
req.send(JSON.stringify(object));
function errorHandler(req, textStatus, errorThrow) {
alert("Error : " + textStatus + ": " + req.statusText);
}
}
*This post is locked for comments