Hello Experts
I'm looking for a way to solve this issue, there is this workflow I'm calling using a ribbon button. It is working fine. But if the user clicks on the button for second time, the workflow is being kicked again. The workflow shouldn't trigger again until first step of workflow is executed. Is there a supported way I can achieve this? Below is the JavaScript code I'm using right now to call workflow using ribbon button.
var isTriggered = false; function MoveMarketplaceOpptyToProposal() { Xrm.Utility.confirmDialog("Do you want to move the stage?", function () { SetValue("se_stage", 534340004); Xrm.Page.getAttribute("se_stage").setSubmitMode("always"); Xrm.Page.data.save(); if (!isTriggered) { executeWorkflows(Xrm.Page.data.entity.getId(), "FC39BB39-ABB0-4D1C-A515-AB63A94B7C4E"); } }, function () { }); } function executeWorkflows(recId, workflowId) { var clientUrl = Xrm.Page.context.getClientUrl(); var query = ""; try { //Define the query to execute the action query = "workflows(" + workflowId + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow"; var data = { "EntityId": recId }; //Create request 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); isTriggered = true; } else { //error callback var error = JSON.parse(this.response).error; isTriggered = false; } } }; req.send(JSON.stringify(data)); } catch (e) { alert("Error occured while executing a Workflow"); } }
Thanks in Advance.
*This post is locked for comments