How to dynamically generate tasks in Custom Task Process in SharePoint Workflow Designer
As you see in that custom task process example, you have to determine the number of assignment stages and recipients before publishing the workflow and it seems it is not possible to change the number of tasks and number of recipients based on some workflow criteria. For example, a workflow may run several times on an item in order to get approval of every participating parties and make it complete, but the first time it has to send to three recipients to approve, and after that if one of the recipients reject the workflow it should goes to just two users to get approval.
Figure 1 – workflow diagrams
In this post I want to introduce a technique for you to tackle this problem and present you a way to dynamically select number of assignment stages and recipients based on some criteria that you define inside the SharePoint designer workflow. To complete this example I use SharePoint designer 2013 and Microsoft SharePoint online. But the custom task process is based on the SharePoint 2010 workflow engine.
In a series of posts, I am describing the different features of Custom Task Process in Microsoft SharePoint designer. You can see a list of link to all posts here.
It is better you first create the simple working example of Custom Task Process in SharePoint designer and then you can check other posts that you are interested in.
First you have to create an additional field in your list, a new column to store whether it is the first time that the workflow is running or not. You have to create this column in your list in order to maintain data between different instances of the workflow. As you see in the previous SharePoint designer custom task process example, we are using a contract list to introduce these features. So I will add a Boolean column to the contact list to store whether it’s a first run of the workflow or not.
Figure 2 – add a Boolean column to contract list
You have to set the default value of this item to Yes.
Then we have to define a new local variable in the SharePoint designer workflow to store the recipients. For example I create a varRecipients variable in my workflow.
Figure 3 – define a new workflow variable
Then I will check whether it is the first time the workflow is running or no
Figure 4 – check whether it is the first time or not
Then if it is the first run of the workflow, I fill out the varRecipients variable with the user A, user B and user C value, and I set the list Boolean column to true. If it is not, I fill out the varRecipients variable with the user B and user C value.
Figure 5 – fill out varRecipients
Then in the custom task process recipients section, instead of explicitly add users to assignment stages, I will add the varRecipients to the receiver field.
Figure 6 – Assignment stages
And you can run your custom task process workflow!
This is how it works:
Figure 7 – first run of the workflow
Figure 8 – next runs of the workflow
The assigned to column is empty for me because I don’t have user A, user B and user C in my online account. If you fill out the data with real usernames, you will be set. But you get the idea!