Please find a snippet code below for executing a workflow from TypeScript.
The only requirement here is to set the WorkflowId and the Id of the record plus the errorMessage and successMessage to use.
Xrm.Utility.showProgressIndicator("Creating .......");
let request =
{
entity: { id: workflowID, entityType: "workflow" },
EntityId: { guid: Id },
getMetadata: function () {
return {
boundParameter: "entity",
operationType: 0,
//operation name is always “Execute Workflow” independent of workflow name
operationName: "ExecuteWorkflow", parameterTypes: {
"entity": {
"typeName": "mscrm.workflow",
"structuralProperty": 5
},
"EntityId": {
"typeName": "Edm.Guid",
"structuralProperty": 1
}
}
}
}
};
Xrm.WebApi.online.execute(request).then(
function (result: any) {
//alert("The confirmation email will be generated.");
debugger;
Xrm.Utility.closeProgressIndicator();
let alertStrings = { confirmButtonLabel: "Close", text: successMessage, title: "Success" };
let alertOptions = { height: 200, width: 400 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
function (success) {
console.log("Alert dialog closed");
},
function (error) {
console.log(error.message);
}
);
},
function (error: any) {
debugger;
Xrm.Utility.closeProgressIndicator();
let alertStrings = { confirmButtonLabel: "Close", text: errorMessage, title: "Error" };
let alertOptions = { height: 200, width: 400 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
function (success) {
console.log("Alert dialog closed");
},
function (error) {
console.log(error.message);
}
);
});
No comments:
Post a Comment