How to Start SharePoint 2013 Workflows on Selected Items
This blog post appeared as an email response to one of our clients, he described a very common use case where you have two libraries of documents, the first library where the users work with draft documents and the other library which is stored the final versions of documents. In this case, users want to be able to select finished documents and move it in one click.
The obvious solution for this is to use a workflow that will move documents to the final document library. But there is one question how we can start the workflow on selected list items? When I was thinking about the answer to that question — I realized that is not as trivial as it seems, because list level workflow can be started only on a single document. How to start multiple workflows on selected documents? In the article, I will describe how you can implement such solution.
I divided this article into three main parts:
- Add custom button to the list ribbon
Before we start, I want to show what we will get in result. On the figure below you can see the custom button on the ribbon, which will launch workflows on selected documents.
As result of execution this snippet of code, you should see the IDs of selected list items in the console log.
How to start workflow
How to Add a Button to the SharePoint Ribbon
Very important part is how a user will interact with our system, I believe that the user experience is very important for any system. In our case, we plan that a user will select the documents and click on the ribbon button which will move them to another document library.
There are various ways to add a button on the ribbon, but in this article, I want to describe the simplest. We will use SharePoint Designer to do this. When we use SharePoint Designer we have some limitation. For example, we can not add new ribbon tab or hide any existing button, but from another point of view if we need just to add a button to the ribbon it will take five minutes of our time and it doesn’t require programming skills.
Please open the SharePoint Designer, navigate to “List and Libraries” and choose your document library.
To add a ribbon button please click inside the “Custom Actions” area and choose on the ribbon “Custom Actions” — “View Ribbon”.
When you fill in the all fields, you should see something like in the figure below in your list.
This is a call of our function with argument “Subscription ID” of our workflow.
Join all of it together
You have to understand what will be the load for the system, for small systems this is an acceptable approach, but for highly loaded systems this is not so good. You can consider other approaches for moving documents like single site level workflow or custom coded solution.
As alternative of this approach, you can start a site level workflow and pass to it the selected IDs, but this is the theme of another article.
Please feel free to comment, I will be happy to answer your questions.