Hello,
I had a customer request recently where the timing parameters may change periodically for certain fields on the form, we love to have workflows for citizen developers who can configure anytime without the need of developers. But to make the execution quick and smooth we love our client scripts. Below is the scenario, where I have to use the JavaScript to call the configurable synchronous workflow to execute quickly from ribbon button.
Knowing the fact that we can’t call the Synchronous events on the Javascript Dynamics V9.1.x, but still can call the RTW synchronously, so for the quick execution of events I have called a RTW from ribbon button trigger event on the form.
This approach was quick and works smooth on latest Dynamics online version.
Code can be found form
//Global parameters
var workFlowId = "{85A87D41-2081-4B35-B5F5-FF0B0B7A99C5}";
var entityRecId = "{E4E53BF4-9AA2-4F7F-8509-4111EAFC38D8}";
var formContext = null;
//Call from the ribbon button, pass the record context like Account, Contact
function ribbonTrigger(primaryControl) {
entityRecId = primaryControl.data.entity.getId();
callRTWfromRibbon(workFlowId, entityRecId);
}
//Function to call Real time workflow from the ribbon button
function callRTWfromRibbon(workFlowId, entityRecId)
{
entityRecId = entityRecId.replace("{", "").replace("}", "");
entityRecId = entityRecId.toLowerCase();
workFlowId = workFlowId.replace("{", "").replace("}", "");
workFlowId = workFlowId.toLowerCase();
var executeWorkflowRequest = {
entity: { id: workFlowId, entityType: "workflow" }, EntityId: { guid: entityRecId },
getMetadata: function () {
return {
boundParameter: "entity",
parameterTypes: {
"entity": {
"typeName": "mscrm.workflow",
"structuralProperty": 5
},
"EntityId": {
"typeName": "Edm.Guid",
"structuralProperty": 1
}
},
operationType: 0,
operationName: "ExecuteWorkflow"
};
}
};
Xrm.WebApi.online.execute(executeWorkflowRequest).then(
function success(result) {
if (result.ok) {
var results = JSON.parse(result.responseText);
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
Environment: Dynamics 365 v 9.1.x
Hope it helped
Coolsama.
Original Post https://mscrmsama.wordpress.com/2020/06/29/calling-a-rtw-from-ribbon-button-on-dynamics-365/