RE: How to update or set status reason field using java script on case entity.
Hi Sandy,
Could you let me know that whether "closed" is a new customization option that you added to Status Reason field of Case entity?
I didn't find an existing case status called "closed" from definition of Case entity, only found "problem solved".

You can run code below to close a case.(resolve a case by "CloseIncident" action)
var guid = Xrm.Page.data.entity.getId().replace(/\{|\}/gi, "").toLowerCase();
var incidentResolution =
{
"subject": "The case has been resolved.",
"incidentid@odata.bind": "/incidents(" guid ")",
"timespent": 60,
"description": "Additional description."
}
var CloseIncidentRequest = function (incidentResolution, status) {
this.IncidentResolution = incidentResolution;
this.Status = status;
this.getMetadata = function () {
return {
boundParameter: null,
parameterTypes: {
"Status": {
"typeName": "Edm.String", //Primitive Type
"structuralProperty": 1
},
"IncidentResolution": {
"typeName": "mscrm.incidentresolution", //Entity Type
"structuralProperty": 5
}
},
operationType: 0,
operationName: "CloseIncident"
};
};
};
var closeIncidentRequest = new CloseIncidentRequest(incidentResolution, 5);
Xrm.WebApi.online.execute(closeIncidentRequest).then(
function (result) {
if (result.ok) {
console.log("Case has been resolved by code.");
}
},
function (error) {
console.log(error);
}
);
You can run code below to reopen a case.(reopen a case by updating its status directly)
var id = Xrm.Page.data.entity.getId().replace(/\{|\}/gi, "").toLowerCase();
var etn = Xrm.Page.data.entity.getEntityName();
var reOpenData =
{
"statecode": 0,
"statuscode": 1
}
Xrm.WebApi.updateRecord(etn, id, reOpenData).then(
function success(result) {
console.log("Case is reopened again.");
},
function (error) {
console.log(error.message);
}
);
Regards,
Clofly