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);
});
};

Advertisement

Author: Indika Abayarathne

MSc in IT [University of Colombo] Solutions Architect | Consultant Technologies: Power Platform | Dynamics CE | Azure

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: