1

I need some help adding a modal dialog box to a java-scripts.

I found this java-scripts code that can be use to start a SP2013 workflow using a calculated column which is working fine. however, i think it will work better on my project if i can add a (YES/NO) modal dialog box to the code.

Can I add a start workflow link to a column in a list view?

Ideally, i should like to present the users with a prompt/dialog box with choices yes/No where YES will start the workflow and NO will just close the dialog box without starting the workflow.

here is the Script: ="<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('Init Workflow: '+wfName+' on 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');" &"}"">Collect Signature</button>"

Gene
  • 81
  • 3
  • 9

1 Answers1

0

It is all JavaScript between those &"" quotes

So with Notepad, you very carefully have to add:

 [existingcode]

 &"if(confirm('You realy want to start this Workflow?'){"

 [existingcode]

 &"}"

 [existingcode]
Danny '365CSI' Engelman
  • 21,176
  • 7
  • 35
  • 79
  • Thanks for the quick reply @Danny. I tried your suggestion multiple times but it does not work. maybe i'm not placing the if confirm condition in the right place.

    if you take a look at your old post Update #1. you add something like &"alert(url);" &"SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog',{url:url});"

    is it possible to use something like &"SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog',{url:url});" instead of SP.UI.Notify.addNotification('Init Workflow: '+wfName+' on item: '+itemID, false);"

    – Gene May 18 '17 at 13:26
  • It is a real pain to check, but it is just JavaScript, each line wrapped in a &" " So you can create a normal JS file, execute it, make it work, then all you have to do is carefully make it a SharePoint string again. – Danny '365CSI' Engelman May 18 '17 at 15:54
  • Here is a bare JS script answer: https://sharepoint.stackexchange.com/questions/160490/obtain-workflow-id-by-title-using-csom/160492#160492 – Danny '365CSI' Engelman May 18 '17 at 15:58