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.

1 workflow design

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.

2 add column

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.

3 local variable

Figure 3 – define a new workflow variable

 

Then I will check whether it is the first time the workflow is running or no

4 check first run

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.

5 update variable

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.

6 fill out recipients

Figure 6 – Assignment stages

And you can run your custom task process workflow!

This is how it works:

7 first run

75 after the first run

Figure 7 – first run of the workflow

 

8 more run

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!

About

MCSE, PMP, With more than 12 years experience in Microsoft technologies.

View all posts by

One thought on “How to dynamically generate tasks in Custom Task Process in SharePoint Workflow Designer

  1. Hi,
    Could you help me in this –
    I need a hierarchical workflow for a SharePoint list.
    Like whenever a new item is created/updated by any user, then one workflow should be initiated to the respective manager to approve it. For example -if an employee inserted an item to this list from HR department then it should approve from HR department manager, If an employee inserted an item to this list from finance department then it should approve from finance department manager, and so on.
    So how we can achieve this type of workflow. I am using SharePoint 2013.

Leave a Reply