I have what may be a familiar piece of code for starting a SharePoint 2013 workflow, except mine fails with an error of "Error: Value cannot be null. Parameter name: subscription undefined." The log I have to check for this never triggers so I'm not sure why the value suddenly isn't being passed properly.
<a href="#" onclick="startWorkflow('2', '947ABD00-0EB4-454D-B561-89CBF6205581')">New Quick Start on 2</a>//using specific item ID to test
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.workflowservices.js"></script>
<script type="text/javascript">
function startWorkflow(itemID, subID) {
var context = SP.ClientContext.get_current();
var web = context.get_web();
var wfServiceManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web);
var subService = wfServiceManager.getWorkflowSubscriptionService()
context.load(subService);
context.executeQueryAsync(
function(sender, args){
var subscription = subService.getSubscription(subID);
if(subscription == null){console.log("Null Subscription")}
if(subscription){
console.log("Subscription load success. Attempting to start workflow.");
var inputParameters = {};
wfServiceManager.getWorkflowInstanceService().startWorkflowOnListItem(subscription, itemID, new Object());
}
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());
}
);
}
</script>