Hello Marina,
I have a button which run a WF on the Form and I am trying to make it work from the HomepageGrid, but I can't get how to change it to make it work.
Here is the code working on the button on the Form:
function createRevision() {
executeWorkflow(
Xrm.Page.data.entity.getId(),
"5ED7322B-AF9C-4DEC-8524-D9AA1EA6073A",
Xrm.Page.context.getClientUrl());
//alert("Text" + Xrm.Page.getAttribute("<fieldschemaname>").getValue());
Xrm.Page.data.refresh(true);
}
function executeWorkflow(entityId, workflowId, clientUrl) {
var functionName = "executeWorkflow >>";
var query = "";
try {
//Define the query to execute the action
query = "workflows(" + workflowId.replace("}", "").replace("{", "") + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow";
var data = {
"EntityId": entityId.replace("}", "").replace("{", "")
};
//Create request
//request url
var req = new XMLHttpRequest();
req.open("POST", clientUrl + "/api/data/v8.2/" + query, false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 200) {
//success callback this returns null since no return value available.
var result = JSON.parse(this.response);
} else {
//error callback
var error = JSON.parse(this.response).error;
}
}
};
req.send(JSON.stringify(data));
} catch (e) {
throwError(functionName, e);
}
}
And here is the command setting for the button:
Could you advise on how to do it?