Skip to content

Instantly share code, notes, and snippets.

@iOnline247
Last active January 20, 2016 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iOnline247/8341141 to your computer and use it in GitHub Desktop.
Save iOnline247/8341141 to your computer and use it in GitHub Desktop.
// Example itemUrl for Document:
// http://<site>/<DocLib>/doc7.docx
// Example itemUrl for Item:
// http://<site>/<customsite>/Lists/<ListName>/<ID>_.000
function fireWorkflow ( itemUrl, workflowName, workflowParams ) {
workflowParams = workflowParams || "<root />";
$().SPServices({
operation: "GetTemplatesForItem",
item: itemUrl,
completefunc: function ( data, status ) {
var workflowGUID = ""
;
$(data.responseXML).find("WorkflowTemplates > WorkflowTemplate").each(function(i,e) {
var $this = $( this )
;
// hard coded workflow name
if ( $this.attr("Name") === workflowName ) {
var guid = $this.find("WorkflowTemplateIdSet").attr("TemplateId");
if ( guid ) {
workflowGUID = "{" + guid + "}";
}
// Stops #each iteration
return false;
}
});
$().SPServices({
operation: "StartWorkflow",
item: itemUrl,
templateId: workflowGUID,
workflowParameters: workflowParams,
completefunc: function( data, status ) {
// Continue processing after workflow is fired.
}
});
}
});
}
fireWorkflow( "http://<site>/Lists/<listName>/<ID>_.000", "Workflow Name", "<Data><TestField>All up in your SharePoints.</TestField></Data>" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment