I have a workflow which I initiate from a list item. Upon initiating the workflow, SharePoint (2010) takes me to a start/initiation page/form (IniWrkflIP.aspx). I don't have any parameters or any other reason to show this page and want to skip it (or somehow autosubmit). I've tried doing this in InfoPath and with Nintex without luck.
2 Answers
Set the workflow to start automatically on item creation -- you can find this option under the "Start Options" section of the workflow creation form (if you're using the UI) and in "Start Options" in the SharePoint Designer workflow editor.
If you want users to choose if and when they kick off the workflow you could create a custom action (or just a plain JavaScript powered button) that can initiate workflows on your selected item.
In JavaScript you need to use SP.WorkflowServices.WorkflowServicesManager
:
A nice solution can be found on code project.
There is also a neat answer on this site about starting a workflow using a calculated column link on each item in your list which may be the easiest thing to implement.
Use following JavaScript code to run workflow manually and you can pass all the initiation values as parameters.
=TEKST.SAMENVOEGEN("<a href=javascript:StartWorkflow(";ApparaatID;",";"'";"{e5859b62-c666-41d0-94be-4df08b86e8d4}";"'";")>ingeleverd</a>")
Function:
function startWorkflow(itemID, subID) {
var context = SP.ClientContext.get_current();
var web = context.get_web();
var wfServiceManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web);
var subscription = wfServiceManager.getWorkflowSubscriptionService().getSubscription(subID);
context.load(subscription);
context.executeQueryAsync(
function(sender, args){
console.log("Subscription load success. Attempting to start workflow.");
var inputParameters = {};
wfServiceManager.getWorkflowInstanceService().startWorkflowOnListItem
(subscription, itemID, inputParameters);
context.executeQueryAsync(
function(sender, args){ console.log("Successfully starting workflow."); },
function(sender, args){
console.log("Failed to start workflow.");
console.log("Error: " + args.get_message() + "\n" + args.get_stackTrace());
}
);
},
function(sender,args){
console.log("Failed to load subscription.");
console.log("Error: " + args.get_message() + "\n" + args.get_stackTrace());
}
);
}