I am trying to start a workflow on the host web from within a web part in an app. Here is my code:
var clientContext = new SP.ClientContext.get_current();
var hostWebUrl = hostUrl;
var hostWebContext = new SP.AppContextSite(clientContext, hostWebUrl);
var wfServiceManager = SP.WorkflowServices.WorkflowServicesManager.newObject(clientContext, hostWebContext.get_web());
var subscription = wfServiceManager.getWorkflowSubscriptionService().getSubscription(subId);
clientContext.load(wfServiceManager);
clientContext.load(subscription);
clientContext.executeQueryAsync(function() {
console.log("Subscription " + subscription.get_name() + " was loaded, attempting to start workflow.");
var inputParameters = { };
wfServiceManager.getWorkflowInstanceService().startWorkflowOnListItem(subscription, itemId, inputParameters);
clientContext.executeQueryAsync(function() {
console.log("Successfully started workflow.");
}, function(sender, args) {
console.log("Failed to start the workflow.");
console.log("Error: " + args.get_message() + "\n" + args.get_stackTrace());
});
}, function(sender, args) {
console.log("Failed to load the subscription.");
console.log("Error: " + args.get_message() + "\n" + args.get_stackTrace());
});
I get an error at the wfServiceManager.getWorkflowInstanceService().startWorkflowOnListItem(subscription, itemId, inputParameters);
line, with the following shown in the console:
Subscription My Test Workflow for the App was loaded, attempting to start workflow.
Failed to start the workflow.
Error: Value cannot be null.
Parameter name: input
undefined
Does anyone have any idea what is wrong? My workflow is a simple workflow, it just updates a field; no input form.