On Dynamics 365, we are trying to close incidents using the client side Web API.
After looking at the doc (in C#), we understand that we first need to create a IncidentResolution activity, which we did successfully. However, we don't understand how to fully close the Incident entity then.
I assume we need to update the record's stateCode and statusCode.. However, if I do so, ajax always return a 500 error.
Other updates are working fine.
Is there anything that we're missing here ?
var entity = {};
entity.statecode = 1; // Resolved
entity.statuscode = 5; // Problem Solved
entity.title = "Title of my case";
var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/incidents(Case's guid)", 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) {
//Success - No Return Data - Do Something
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));