Hello!
I have SharePoint list with calculated column, which contains script to make it a button. Button is running workflow on click.
="<button style=""cursor:pointer;"" onclick=""{"
&"event.preventDefault();"
&"function startWorkflow(itemID, wfName) {"
&" function __startWorkflow() {"
&" var ctx = new SP.ClientContext.get_current(),"
&" wfsManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx,ctx.get_web()),"
&" wfSubs = wfsManager.getWorkflowSubscriptionService().enumerateSubscriptionsByList(_spPageContextInfo.pageListId);"
&" ctx.load(wfSubs);"
&" ctx.executeQueryAsync(function () {"
&" wfsEnum = wfSubs.getEnumerator();"
&" while (wfsEnum.moveNext()) {"
&" var wfSub = wfsEnum.get_current();"
&" if (wfSub.get_name() === wfName) {"
&" wfsManager.getWorkflowInstanceService().startWorkflowOnListItem(wfSub,itemID,new Object());"
&" SP.UI.Notify.addNotification('NOTIFICATION_FOR_ITEM:'+itemID, false);"
&" }}});}"
&" if (!SP.WorkflowServices) {"
&" var script = document.createElement('script');"
&" script.src = '/_layouts/15/sp.workflowservices.js';"
&" script.onload = __startWorkflow;"
&" document.head.appendChild(script);"
&" } else {__startWorkflow();}"
&"}"
&"var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}"
&"startWorkflow(TR.id.split(',')[1] , 'YOUR_WORKFLOW_TITLE_GOES_HERE');"
&"}"">NAME_OF_BUTTON</button>"
The workflow only launches if you double-click the button. A single click displays the Notification but does not start the workflow.
Also it launch after first click if I am doing it for more than one item on list, but in this case it is working for every clicked item except the last one.
Script is working fine, the thing is in workflow somehow as I think.
Changing the workflow doesn't help, issue appears for every workflows and for every items (new ones, old ones and etc).
Could you please help me to find the solution or some workarounds?