Nintex Workflow

Nintex Workflow – Iterate through Related Collections

With the abilty to query multiple values from an XML document or a SharePoint List using Nintex Workflow actions, a number of people have come to me and asked for a nice way to iterate through each collection and get corresponding values from each collection.

One of the more common business scenarios is trying to get the data from fields in a Repeating Section of an InfoPath form.

Here is a simple InfoPath form with 3 fields.  A first name, last name and location.

When a user fills in this forms, since it’s a repeating section, they can add many records.  In this example, I just have 3 records.  What I would like to do is go through each record. 

An InfoPath form is basically an XML document.  That means that  you can use the Nintex Workflow Query XML action to get data out of it.  This action now supports multiple queries in the one action.  Since we want to get 3 bits of data, instead of having 3 Query XML actions, you just have the one.

In our example, we want to get the First Name, Last Name and Location from our repeating section.  Since there can be many first names, last names and locations, we need to first look at the structure of our InfoPath Form XML.

Based on the XML, we need an XPath expression for each piece of data we want (one for First Name, one for Last Name and one for Location).

First Name : //my:group1/my:group2/my:field1

Last Name : //my:group1/my:group2/my:field2

Location : //my:group1/my:group2/my:field3

Each query will store the results in their respective Collection variables: collFirstNames, collLastNames and collLocations.

Iterating Through the Related Collections

Now we want to get each value and their matching other values from the collections and do something with them.

To do this, we need the following variables:

1. numIndex : Number variable that will store the index into the collections as we iterate through them.

2. textFirstName : Text variable that will store the current First Name

3. textLastName : Text variable that will store the current Last Name

4. textLocation : Text variable that will store the current Location

We then add a For Each action to our workflow.  This action is configured to go through the collFirstNames collection variable, store the result in the textFirstName variable and the index in numIndex.

This will give us a first name.  Now we add a Collection Operation action inside the For Each to perform a Get on the collLastNames, and we want to retrieve the value from the collection at the position of the numIndex and store it our textLastName variable.  We will also add another Collection Operation to do the same thing for the Locations.

At this stage of the For Each, we have all the values corresponding to the same position in each Collection operation and we can do what we need.  In this example, I’m just going to log them to the workflow history, as it’s a good idea to do that for debugging purposes.


That is all the workflow logic you need to get the related values from collection variables.Download

Nintex Workflow 2010 : v2.3.3.0

Download the Workflow

Download the InfoPath Form XML

Download the InfoPath Form XSN

Leave a Reply