The code is below. My workflow name is 'myWorkflow'

Question 1 Why doesn't this WF work? It is allowed to start manually and it is a single step: Set 'Read' to YES End Workflow

="<button style=""cursor:pointer;"" onclick=""{"
&"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] , 'wfRead');"
  • 1
    Q1: afaik: this starts associated workflows (but I never used it) Q2: No: this code says: Hey workflow you start! If you want a signal back you have to do that at the end of the workflow, and then this code has to wait for it. FYI: extract all this code and make it work in F12 Dev Tools first – Danny '365CSI' Engelman Dec 15 '15 at 19:26
  • 1
    Does the Workflow Template ID change each time the same workflow is run? Sometimes it'll work, and other times, it won't. If we forget question #2 for a second, what is wrong with my script that it won't fire and run every time? Is this script only for a List? I'm very confused. – TheJDScott Dec 15 '15 at 19:47
  • 1
    The Workflow ID changes for every new (Published) version of the Workflow; that is why so much mumbo jumbo to get hold of the correct ID is required. If you never update the Workflow definition you can hardcode the ID – Danny '365CSI' Engelman Dec 15 '15 at 20:17
  • 1
    What do you mean by 'workflow definition'? In your opinion, what's the ideal Workflow type that will work every time? – TheJDScott Dec 15 '15 at 21:55
  • Not workflow Types.. Every time you Update a Workflow (not Run!) it is re-published and gets a new id – Danny '365CSI' Engelman Dec 16 '15 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.