AnsweredAssumed Answered

Start a workflow from a button error

Question asked by ougatre on Mar 21, 2016

Hi,

To start a site workflow from a button in the document page (as shown in the picture below) I use this script :

<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.core.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.workflowservices.js"></script>

<script>
function startWorkflow() {
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var wfServiceManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web);
context.load(wfServiceManager);
var workflowSubscriptionService =  wfServiceManager.getWorkflowSubscriptionService();
    var subscription = wfServiceManager.getWorkflowSubscriptionService().getSubscription("Workflow Id");
context.load(subscription);
    context.executeQueryAsync(
        function(sender, args){
            console.log("Subscription load success. Attempting to start workflow.");       
            var inputParameters = {};
            wfServiceManager.getWorkflowInstanceService().startWorkflowOnListItem(subscription, null, 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());
        }
    );
}
</script>

I got this error:
Failed to load subscription.
Error: Cannot invoke method or retrieve property from null object. Object returned by the following call stack is null. "GetWorkflowSubscriptionService
new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager()"
undefined

 

Does anyone know how to resolve it please?

Thanks

 

Attachments

Outcomes