Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show how to find and run a workflow by its name #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/core/web-services/Workflow/GetTemplatesForItem.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,46 @@ $().SPServices({
}
});
```

An example from [dsMagic12](https://github.com/dsmagic12), showing how to find and execute a list workflow by the workflow's name:

```javascript
var listURLName = "Tasks";
var itemId = 1;
var workflowName = "Kickoff This Workflow", workflowGUID = "";
/* first call a web service to get all of the workflows that could be run on the item in our list */
jQuery().SPServices({
async: true,
debug: true,
operation: "GetTemplatesForItem",
item: jQuery().SPServices.SPGetCurrentSite() +"/Lists/"+ listURLName +"/"+ itemId +"_.000",
completefunc: function(xDataGetTemplatesForItem, StatusGetTemplatesForItem) {
try{console.log("Got all of the workflow templates for item |"+ itemId +"| in list |"+ listURLName +"|");}catch(er){}
try{console.log(xDataGetTemplatesForItem);}catch(er){}
try{console.log(StatusGetTemplatesForItem);}catch(er){}
/* loop through the workflows associated with this list and item */
jQuery(xDataGetTemplatesForItem.responseXML).find("WorkflowTemplates > WorkflowTemplate").each(function(i,e) {
/* find our workflow by its name, then capture its GUID */
if ( jQuery(this).attr("Name") === workflowName ) {
try{console.log("Found the workflow template for this list item that matches our target workflow name");}catch(er){}
workflowGUID = jQuery(this).find("WorkflowTemplateIdSet").attr("TemplateId");
/* now start our workflow on our item */
try{console.log("Sending web service request to start the workflow");}catch(er){}
jQuery().SPServices({
async: true,
debug: true,
operation: "StartWorkflow",
item: jQuery().SPServices.SPGetCurrentSite() +"/Lists/"+ listURLName +"/"+ itemId +"_.000",
templateId: workflowGUID,
workflowParameters: "<root />",
completefunc: function(xDataStartWorkflow, StatusStartWorkflow) {
try{console.log("Started workflow on item |"+ itemId +"|");}catch(er){}
try{console.log(xDataStartWorkflow);}catch(er){}
try{console.log(StatusStartWorkflow);}catch(er){}
}
});
}
});
}
});
```