I am in the process of upgrading from V8.2 to V9.0, the JS code is fine in V8.2
function closeCase(){
debugger;
var caseId = Xrm.Page.data.entity.getId();
var context;
caseId = caseId.replace("{", "").replace("}", "");
var incidentresolution = {
"subject": "My Subject",
"incidentid@odata.bind": "/incidents(" caseId ")",//Id of incident
"timespent": 60,
"description": "My Description"
};
var parameters = {
"IncidentResolution": incidentresolution,
"Status": -1
};
if (typeof GetGlobalContext === "function") {
context = GetGlobalContext();
} else {
context = Xrm.Page.context;
}
Xrm.Page.data.save().then(
function(){
alert("Form Save Successfully");
var req = new XMLHttpRequest();
req.open("POST", context.getClientUrl() "/api/data/v8.2/CloseIncident", 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) {
alert("Case Closed");
Xrm.Page.data.refresh(false);
}
else {
var errorText = this.responseText;
alert("Case not Closed" errorText);}
}
};
req.send(JSON.stringify(parameters));
},
function(errorCode,message){
alert("Save Failed " message);
});
}