pesikwane

Assigning Tasks Dynamically: A practical example

Blog Post created by pesikwane on Nov 17, 2017

Greetings everyone  

 

You might remember my previous post where I illustrated how you can dynamically build a list of approvers and assign tasks to them in a loop via a Nintex® Workflow. In this post I've included an example  .

 

 

AuthorPalesa Sikwane
Long DescriptionWant to Create a list of approvers dynamically using Nintex Workflow? This is the post for you!
Dependencies

Nintex® Workflow for Office 365®, SharePoint Online® (Office 365®)

Support Info

Palesa Sikwane

Additional Information

N/A

 

My previous post Assigning Tasks Dynamically Using Start a Task Process in NWF0365 can be summarised as: 

 

1. Querying a List of Approvers

 

2. Assigning Tasks for Each Brand Dynamically

 

Step 1: Querying the list of approvers

I have configured a list containing my Approval matrix per brand name (I went with cereal brands as an example   ):

 

Brand NameApprover NameDeputy Name
WeetbixPalesa Emmanuel SikwaneRichard Roe
KellogsRichard RoePalesa Emmanuel Sikwane
Jungle OatsJane DoeJane Doe

 

 

This is the list I query in the workflow using the Query List Action, coupled with a few other actions. So i've built a Workflow containing a State Machine, and 2 States:

 

1.  Initial and ;

2. Assign Tasks. 

 

In the Initial State I perform the following steps:

 

ActionDescription

Here I set my workflow status column to : 
"Workflow Started Successfully"

Here I query the Approval Matrix list using the following configuration:

 

 

 

 

 

Note:

Here I simply query all items in my Approval Matrix list (returning 100 items) and output the following data into collection variables:

 

- ID of all my brands (into collBrandID)

- Brand Names (into collBrandName)

 

I also output the number of results returned into a variable called numBrands

Here I log to my history list how many Brands are returned in numBrands
Here I used a Set Next State action to jump to the next state of my workflow called Assign Tasks.

 

Step 2: Assigning Tasks for each Brand Dynamically:

 

This is the second and final state of my workflow and it has the following configuration:

 

ActionDescription

Here I set my workflow status column to:

" Assigning Tasks "

 

 

 

 

 

ActionDescription

The next step is a For Each which will allow us to iterate through the information returned in our  step in our Initial State.

 

This step is configured as follows:

 

Note:

 

- Here I basically iterate through my collBrandID collection which stores all of the ID's of my Brands in the Approval Matrix list. 

- I then set my Output value to a variable called BrandID to store the current brand I am iterating through in the loop. 

- I keep track of each Brand ID in a variable called BrandIndex (which automatically changes when the For Each iterates to the next BrandID)

 

Just a couple of notes on collections: 

- Collections ALWAYS have an Index beginning at 0

- Collections store multiple values into a single collection variable. When I think of collections I think of data been stored in a block. For example a collection containing 3 brands would look like:

 

 

And if we put the index next to each Brand Name(and applying the rule that indexes begin at position 0)

 

Weetbix is at position 0

Kellogs is at position 1
Jungle Oats is at position 2

So we can at any time pull out a specific value (using a Get Item from Collection action) OR iterate through all the data using the index to help us keep track of each value in the collection using a For Each action, which automatically increments the index for us as it reads each value out of the collection.

 

Note:

 

- In this step i get the ID of each Brand because its Unique, meaning that you'll never get items with the same ID in the SAME list

 

- Collections store multiple pieces of information, which are usually separated with a semi colons or in some cases commas (i.e. " ; " or " , ") and square brackets (i.e. " [ " or " ] "  ). This makes it easier for Nintex Workflow to separate each piece of data when we iterate through it or pull out a specific value.

In this step based on the Index, I read the each item out my collection and get the corresponding Brand Name. Remember in my For Each i get the Brand ID and iterate through those

 

Note:

This runs in the loop and will repeat x number of times, where x is the number of items we find.

In this step for record purposes, I log the current Brand Name and the Brand ID that the workflow has picked up

Here I query my Approval Matrix list where I take the current Brand ID, to query my Approval Matrix and return in collection variables:

 

- Approver Name for the specific Brand

- The name of the Deputy for that specific Brand

 

Note:

We're using the Brand ID as a filter which is Unique, and will ensure that for the Approver Name and the Deputy; although both are stored in collection variables; there will be one value for each, and because we expect one value, that value will always have an Index of 0 . 

I then log the following to my workflow history (for record purposes):

 

- Brand Name

- Approver

- Deputy

1. I use a Parallel Block to run the next set of steps at the same time, in this example this is perfect, as the SAME steps need to occur for both the Approver and the Deputy we pick up when we query our Approval Matrix.

 

Note:

Parallel blocks are great for structuring your workflow, but also ensuring that things happen at the same time, in my example I used this for that purpose but also to make it easier for me to explain the workflow. 

 

 

2. I then(for both the Approver and the Deputy) take the collection variable(s) returned and set them to their corresponding text variables (I use this data later on in my regular expressions below).

 

3. In this first regular expression I remove the square brackets that are part of my collection where I return the Approver Name as well as the Deputy. I replace these with blank text. I set the following configuration:

 

 

 

 

4.In this second regular expression I take the result returned above and replace my commas with semi colons. I do this because when you specify multiple email 

they are usually separated by semi colons, and if you guys remember in this post I want to Assign Tasks to multiple people dynamically; and to do this I use my loops to deteremine who should get the tasks and build the list or task participants using . I use the following configuration:

 

The last thing I do in the loop is use a Task Process to Assign my tasks dynamically to the email addresses i've determined in the previous step. The action is configured as follows:

 

I set the Assign options as follows:

 

 

Note:

 

As you guys can remember in my previous post the Start a Task Process workflow action is aimed towards Assigning a task to a group of Users, and allows workflow designers to specify task assignment criteria (Assign tasks all at once or in serial) as well as completion criteria (Wait for all responses, Wait for first response, Wait for specific response or Wait for percentage of a response). 

 

This functionality allows us to control how we would like to Assign the tasks to Approver and the Deputy as required, i.e.

 

- In series (one after the other); this option works really well if Assign Tasks to users in a SharePoint Group, this has been discussed in this post here,

- In parallel (all at once) 

 

The advantage of this is that it will allow you to be dynamic  . So if you have a complex process that requires you to cater for both scenarios without having to make changes to the workflow this can be utilised really well. 

 

Also now that we have the schedule workflow feature available on office 365, Brad Orluk has a good blog post on this new feature titled: Tee Up Your Work - Scheduled Workflows Are Available for Office 365! ; be sure to check it out

 

 

In any case i'll  probably cover this in a follow up post  to show you guys how you can use this to your advantage. 

 

 


I hope this helps someone out there

 

Cheers

Outcomes