StartWorkflow

Function

$().SPServices

Web Service

Workflow

Operation

StartWorkflow

Example

This example comes from a great article over at NothingButSharePoint.com by Jason MacKenzie (Intelligence Among Us). In it, Jason shows how you can use a call to StartWorkflow to improve the user experience with, you guessed it, starting a workflow. I'm only going to include the SPServices snippet from the article; read the whole article to see it in context.

Note the trick with the workflowParameters option, where Jason passes an XML node.

<script type="text/javascript" src="/sites/sprc/Resources%20%20jQuery/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/sites/sprc/Resources%20%20jQuery/jQuery%20SP%20Services/jquery.SPServices-0.5.4.min.js"></script>
<script type="text/javascript">

function StartWorkflow(ItemURL, ItemID) {
  var loadingImage = ‘Loader’ + ItemID;
  var workflowDiv = ‘WorkflowDiv’ + ItemID;
  //Show our loading image
  document.getElementById(loadingImage).style.visibility = ‘visible’;
  $().SPServices({
    operation: "StartWorkflow",
    item: ItemURL,
    templateId: "{04ee1c93-f6b7-49b3-a79c-fa3142ecd688}",
    workflowParameters: "<root />",
    completefunc: function() {
      document.getElementById(workflowDiv).innerHTML = ‘Workflow Started’;
    }
  });
}
</script>

Here's another example from Rkbradford which shows how you can pass workflow parameter values:

$().SPServices({
  debug:true,
  operation: "StartWorkflow",
  async: true,
  item: "https://server/site/Lists/item" + idData + "_.000",
  templateId: "{c29c1291-a25c-47d7-9345-8fb1de2a1fa3}",
  workflowParameters: "<Data><monthName>" + txtBox.value + "</monthName></Data>",
  ...
});

alan_usa provided a tip that, when passing more than one parameter, the syntax should be:

workflowParameters: "<Data><Parameter1>" + parameter1 + "</Parameter1><Parameter2>" + parameter2 + "</Parameter2></Data>"

Back to top