Hi,
That code still work but I have changed few
function check() {
var entity = {
"EntityId": Xrm.Page.data.entity.getId().replace("{","").replace("}","") // accountId
};
var WorkflowId = "2025DDE0-66E5-47D7-8611-2AD5F3306D69"; // workflowID For getting Workflow Id You can see below image and also what steps you add
var req = new XMLHttpRequest();
req.open("POST", Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.1/workflows(" + WorkflowId + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow", true); // mention what version you are using I am using 9.1
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 === 200) {
Xrm.Navigation.openAlertDialog("Success",null);
Xrm.Page.data.refresh();
} else {
Xrm.Navigation.openAlertDialog('Already inactive or Error',null);
}
}
};
req.send(JSON.stringify(entity));
}
Now Xrm.Page is not been replaced even in this code because we cannot get the formcontext is working for UI or normal web client when we use to call javascript function through ribbon workbench. I also get null value when using from web client. UI its working fine. For that you can check this link for more explaination
https://stackoverflow.com/questions/48202316/how-to-get-formcontext-in-ribbon-command-of-dynamics-365-9-0
other than Xrm.Page . I Changed all the deprecated code
Hope it helps