Nintex Workflow – ToDo Task Parallel Processing
In contrast to the Nintex Workflow Request Data action, which only supports getting data from a single user, the Assign a ToDo Task can assign tasks to many users. Often, you may have a single Assign a ToDo Task action, assigning tasks to several people. For this example, lets say it’s 3 people. This action will then sit and wait for all 3 users to complete their tasks before the workflow will continue.
But, lets say you have a business requirement where by if one of those users fills in an exorbitant amount for some field of the task and completes the task, you want to catch that as soon as possible and do something about it. You may not necessarilly want to stop the Assign a ToDo Task, but you may want to notify the manager or IT because the faster something gets done, the better.
Or how about a different scenario. You assign a ToDo task to 3 users, 1 of which is a Managing Director. You want to get data from all users, but if the Managing Director chooses to say No to a particular field in the task, then you need to notify the other users.
In both scenarios, the Assign a ToDo Task will wait and you won’t be able to do anything until every task is completed.
We need a solution whereby we can figure out how many tasks we need to look at. We can type this in at design time, but it would be more robust if we could figure it out at runtime.
1. Problem one : find out how many tasks we have
The default tasks list for Nintex Workflow is called Workflow Tasks. All tasks will be created in this list. To narrow down the search, we can search for all tasks created by the current workflow instance. We do this by querying the Workflow Tasks and compare the Workflow Instance ID of the task to the Workflow Instance of the running workflow.
This will narrow it down a little, but we need more.
A workflow can have multiple task related actions. How do we narrow it down?
One way would be to give the Tasks a unique name. But that can get messy. Instead, just before the Assign a ToDo Task action, we add a Calculate a Date action. We configure this to store the current date and time in a Date/Time variable. Now in our query, we can search of all tasks that have the current Workflow Instance ID and also those whose Created field is greater than or equal to our stored DateTime. This will find all tasks created by this workflows after a specific date and time.
NOTE: I can think of one scenario where this may not work. If you have Task related action in parallel branches, the Query List action will find all the tasks and not ones specific to a task action. But how often does this happen?
Now that we can query for all the tasks, the results can be stored into a Collection variable and we can get the count using a Collection Operation action.
2. Problem two : loop through all the tasks until all are completed
For this post, we’ll simply build logic that will loop until all the tasks are completed. If you want more, list retrieving the data from the tasks and doing something with it, you can simply add to this logic of the workflow that is downloadable at the bottom of this post.
Since we know how many tasks we have, we now have to keep a running tally of processed users and we continue looping until we have processed every task.
We use a Loop action configured to compare the total number of user tasks to the running tally. Since I work in an environment which has Safe Looping disable (I don’t recommend this), I have added a Pause at the bottom of the loop. This will pause for 1-5 minutes and will prevent Loop going crazy constantly querying the Workflow Tasks list.
Two things are important in the loop.
a. The Query List action now queries for tasks for this workflow instance, that were created after our stored data and also where the Status = Completed. This means we only received completed tasks and minimizes our processing.
b. It checks again if we have processed all the users. If we haven’t, only then does it do the pause. Otherwise, since we’ve processed all the users tasks, the loop can exit out and the workflow can continue.
You may find that the Content Type the Assign a ToDo Task action is using doesn’t exist in your environment. You can just create a dummy one for this test and use that.
Hopefully this post will show you that you can do things with the Assign a ToDo Task actions “tasks”, even though the action itself will sit and wait until the task is complete.
If you wanted to manipulate the tasks, you could look at using the Update Item action and set the Status to “Completed” and I like to set the % Complete to 100 also.