cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Not applicable

Start Workflow for selected List Items

Jump to solution

Hi there,

i currently have a little problem with one of my projects. Here's what i try to do. I want to be able to select some List items and then run a function that starts a specific work flow for this itme. To accomplish this I more or less used the code if found on c-sharpcorner.com Unfortunately i always get an error message stating:

Failed to load subscription

Error: Ungültige Anforderung. undefined (translated: invalid request)

I'm not completely sure if i get the subscriptionID right which might be a point (Link looks like /StartWorkflow.aspx?List={4ccda439-0067-47f8-a452-30d4f4d2c173}&ID=2&ItemGuid={E8C7E0FA-DCAB-4475-9994-FE9BD9566D96}&TemplateID={710e22fa-2ffc-4f0b-bf47-9da7f74aff00} so i guessed the first id {4ccda... must be the right one even though i tried the function with all of them)

If its not the ID I'm a little lost at the moment. It would be great if someone came up with an idea. Thanks in advance and

Greetings Chris

websiteWorkflows = (function() { 

    var self = this; 

    self.Context = null, 

    self.WFManager = null; 

 

    SP.SOD.executeFunc("sp.js", "SP.ClientContext", function() { 

        SP.SOD.registerSod('sp.workflowservices.js', SP.Utilities.Utility.getLayoutsPageUrl('sp.workflowservices.js')); 

        SP.SOD.executeFunc('sp.workflowservices.js', "SP.WorkflowServices.WorkflowServicesManager", 

 

        function() { 

            self.Context = SP.ClientContext.get_current(); 

            var web = self.Context.get_web(); 

            self.WFManager = SP.WorkflowServices.WorkflowServicesManager.newObject(self.Context, web); 

        }); 

    }); 

 

    StartListWorkflowOnSelectedItems = function(subID) { 

        var selectedItems = SP.ListOperation.Selection.getSelectedItems(self.Context); 

 

        for (item in selectedItems) { 

            var itemId = selectedItems[item].id; 

            self.StartListWorkflow(itemId, subID); 

        } 

    }; 

 

    StartListWorkflow = function(itemID, subID) { 

        var subscription = self.WFManager.getWorkflowSubscriptionService().getSubscription(subID); 

 

        self.Context.load(subscription); 

        self.Context.executeQueryAsync( 

 

        function(sender, args) { 

            var inputParameters = {}; 

 

            self.WFManager.getWorkflowInstanceService().startWorkflowOnListItem(subscription, itemID, inputParameters); 

 

            self.Context.executeQueryAsync( 

 

            function(sender, args) { 

                var message = "The workflow " + subscription.get_name() + " was started on item with ID " + itemID; 

                SP.UI.Notify.addNotification(message, false); 

            }, 

 

            function(sender, args) { 

                var message = "Failed to start workflow " + subscription.get_name() + " on item with ID " + itemID; 

                SP.UI.Notify.addNotification(message, false); 

                console.log("Failed to start workflow."); 

                console.log("Error: " + args.get_message() + "\n" + args.get_stackTrace()); 

            }); 

        }, 

 

        function(sender, args) { 

            var message = "Failed to load subscription " + subID; 

            SP.UI.Notify.addNotification(message, false); 

            console.log("Failed to load subscription."); 

            console.log("Error: " + args.get_message() + "\n" + args.get_stackTrace()); 

        }); 

 

    }; 

 

    return { 

        StartListWorkflow: StartListWorkflow, 

        StartListWorkflowOnSelectedItems: StartListWorkflowOnSelectedItems 

    }; 

})();

Labels: (1)
0 Kudos
Reply
4 Replies
Highlighted
Nintex Newbie

Re: Start Workflow for selected List Items

Jump to solution

If you're using Nintex workflows then you can use the code I've posted in answer to this question, Start a workflow from a hyperlink in a list/library view?

Jan

View solution in original post

Reply
Highlighted
Not applicable

Re: Start Workflow for selected List Items

Jump to solution

Thanks for the quick reply. I've been playing around with it but now i get this error Message back

POST [website]/_vti_bin/NintexWorkflow/Workflow.asmx 500 (Internal Server Error)

I also tried calling the startworkflowonlistitemcsr directly and filled in values for wfName, itemId and listName manually. Unfortunately without any look.

Since my Workflows point to

[website]/_layouts/15/NintexWorkflow/... i also tried this. After that I don't get the 500 but the Workflow still isn't starting

0 Kudos
Reply
Highlighted
Not applicable

Re: Start Workflow for selected List Items

Jump to solution

OK, that worked. Something was wrong with the SOAP-Request. No idea what I did wrong at first. Just a little thing i added which you might find helpful. I used this to get the ID so you don't have to have an ID-Column.

Thank you and

Greetings;

StartWorkflowOnSelectedItems: function(WfName, ListName){

$(SP.ListOperation.Selection.getSelectedItems()).each(function(){

startworkflowonlistitemcsr(WfName, this.id.toString() , ListName);

});

}

0 Kudos
Reply
Highlighted
Nintex Newbie

Re: Start Workflow for selected List Items

Jump to solution
Could you share details on how to get it implemented? I’m looking into a way to start a Nintex workflow on multiple selected items. Thank you
0 Kudos
Reply