0

I am trying to start a site workflow(2013) created on my site using the below code.

function StartWorkflow(subscriptionId){
var params = new Object();
params = {param1:'<param1>'};
var ctx = SP.ClientContext.get_current();
var wfManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx,
ctx.get_web());
var subscription = 
wfManager.getWorkflowSubscriptionService().getSubscription(subscriptionId);
ctx.load(subscription, 'PropertyDefinitions');
ctx.executeQueryAsync(
    function(sender, args)
    {
        wfManager.getWorkflowInstanceService().startWorkflow(subscription, params);

    },
            function(sender, args)
            {
                alert('error');
            });

   }            

   var scriptbase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";    
            $.getScript(scriptbase + "SP.Runtime.js", function () {
                $.getScript(scriptbase + "SP.js", function () {
                    $.getScript(scriptbase + "SP.WorkflowServices.js", function () {
                        StartWorkflow('<subscriptionId>');
                    });
                });
            });

the code runs without any error but my workflow doesnt start. However I am able to run a list workflow successfully using the above code by adding listID as 2nd parameter for startWorkflow method. I assume that the subscriptionId is the templateId query string of the Workflow Initiation form URL

<sitename>/wfsvc/<someGUID>/WFInitForm.aspx?TemplateID={xxxxxxxx}&WF4=1&source=<url>

Please clarify.

1 Answer 1

0
wfManager.getWorkflowInstanceService().startWorkflow(subscription, params);
ctx.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());
}
); 

Try this executeQueryAsync() once again inside the executeQueryAsync()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.