Workflow must be in Published state

The above error message is displayed in Dynamics 365 and most of the developers\users will look around workflows as the error says “Workflow must be in Published state.”

E.g. Creating a case throws the above error with the following details.

[Microsoft.Crm.Service.GlobalSlaPlugin: Microsoft.Crm.Service.GlobalSlaPlugin.SlaPostCreatePlugin]
[ebd908b4-2c74-e811-a95d-000d3ae0bc37: ObjectModel Implementation]

The issue is with SLA records associated with Case.

Deactivating SLA records and reactivate them back will resolve the issue.

 

Status Change using WebApi

In Dynamics 365, OOTB status field value can be changed in many different ways.

Following WebApi can be used to update the Status (statecode + statuscode) as follows.

changeStatus = function (executionContext, entityLogicalName, recordId, statecode, statuscode) {
// Remove brackets from the GUID if there’s any
var id = recordId.replace(“{“, “”).replace(“}”, “”);
// Set statecode and statuscode
var data = {
“statecode”: statecode,
“statuscode”: statuscode
};
// WebApi call
Xrm.WebApi.updateRecord(entityLogicalName, id, data).then(function  success(result) {
executionContext.getFormContext().data.refresh(true);
}, function (error) {
executionContext.getFormContext().data.refresh(true);
});
};