0

There's been a lot of posting on here about this topic, and I can't seem to find a definitive answer here (or anywhere else online). In SP13, when viewing the source of a SP Workflow button, the code is rendered as javascript. Neither of the GUIDs presented seem to be the Workflow's Template ID.

I'm trying to make a URL to manually start a Workflow, and I keep getting routed to an error screen. I'm pretty certain that I don't have the proper WF Template ID. This is what I have so far:

="<a href=http://portal/_layouts/15/IniWrkflIP.aspx?List{F4E6RD31-1FD9-4559-N7AA-892B212FDB93}&ID={ID}&TemplateID={E92B2B59-DF72-48B1-9FFB-42F9789E6RDE}&?Source= http://Main/Lists/Contacts/AllItems.aspx"
Eric Alexander
  • 43,293
  • 10
  • 53
  • 93
TheJDScott
  • 123
  • 4
  • 22

1 Answers1

1

yes, it requires some javascript code, but you can stuff it in a Calculated Column, so no need for Visual Studio or Designer

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

Change the second-last line to your Workflow title,

Copy/Paste in a Calculated Column, set the datatype to Number

="<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>"
Danny '365CSI' Engelman
  • 21,176
  • 7
  • 35
  • 79
  • Thank you for the quick and thoughtful response! I am going to try this out and get back to you ASAP – TheJDScott Dec 14 '15 at 21:59
  • Wow. Incredible. This really helped me out so much. Just for kicks, do you know where I can edit/add a source URL in the script so the page refreshes on click, as well? – TheJDScott Dec 14 '15 at 22:09
  • Danny, this isn't working for me. It just stopped. I press the button, and the alert pops up on the top righthand corner, but then nothing happens after that. I copied and pasted the code, and put my Workflow Name 'sendEricAnEmail' in place of 'YOUR_WORKFLOW_TITLE_GOES_HERE'. the WF doesn't actually take place. Any idea what I could be doing wrong? – TheJDScott Dec 15 '15 at 00:46