Vadim Tabakman

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.

Conclusion

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

Posted by Vadim Tabakman Tuesday, June 5, 2012 12:53:00 AM Categories: Collection Operation Collection Variable For Each Nintex Workflow Query XML
Copyright Vadim Tabakman
Rate this Content 0 Votes

Comments

Tuesday, July 10, 2012 3:32:55 AM
Michael

re: Nintex Workflow - Iterate through Related Collections

Hallo Vadim,

would this work, if one last Name Node was empty? Would the last name Collection in this example contain three values?, or only two? And when iterating through the collections, values would not run out of order?

Thanks, I like your site!

Best regards
Michael

Tuesday, July 10, 2012 10:41:37 AM

re: Nintex Workflow - Iterate through Related Collections

Hi Michael,

In this example, all collections would need to be the same size.  If they weren't, there no way to make sure the values you retrieve will be related values.  Also, inside the For Each, where we are doing a Collection Operation to perform a "Get".  If this tries to get a value from a collection at an index greater than the size of the collection, the workflow will most likely fail.

If you expect something like this, yo may need to put in some checks before going into this type of processes to make sure all collections are the same size.

Friday, July 26, 2013 8:53:25 AM
Juli Reid

re: Nintex Workflow - Iterate through Related Collections

So if my repeating list only had one column (Location) that I am wanting to get into a collection to use for task assignment, do I still need the numberID? 

Tuesday, September 16, 2014 1:01:13 AM
bcobra
Gravatar

re: Nintex Workflow - Iterate through Related Collections

Vadim,

Reading your blog makes my life so much easier. Thanks for the blog. I have one two part question related to this article. How would you do this if one of the fields in the InfoPath repeating tablw was a multi select (LastName, FirstName, Location, Owned) where owned could be car, house, condo, vaction home, jet ski, boat, other? How would you populate these values into a multi value lookup? Thanks

Tuesday, September 16, 2014 11:32:44 PM

re: Nintex Workflow - Iterate through Related Collections

Hi bcobra,

Are you try to read data from an InfoPath form or populate a field with data?

Vadim

Monday, September 22, 2014 10:52:15 PM
bcobra
Gravatar

re: Nintex Workflow - Iterate through Related Collections

Both. I am reading data from a form to populate another list
Thursday, October 23, 2014 7:05:58 PM
Marcy
Gravatar

re: Nintex Workflow - Iterate through Related Collections

Hi, there. Thanks for your great post. I was happily following along and then got this error:  Error operating on collection variable: Index property is greater than the number of items in the collection. I think you alluded to this  when you said all collections have to contain the same number of items. Since people don't always answer every field in my form, there will be a variance in the number of items in the collection. Is there a way I can account for this in my workflow? Unfortunately, I'm not a coder so was loving your method of getting each item from my repeating section as its own item on my SharePoint list. Thanks so much.

Friday, October 24, 2014 3:01:54 AM
bcobra
Gravatar

re: Nintex Workflow - Iterate through Related Collections

Hi Vadim just wondering if you had time to think about my question?  How do you make values in a sub collection a single value in an outer collection? Ex:

FirstName    Last Name   Location    Owned

Bill                Cobra                FLA                House;Boat;

John               Smith           GA                  Condo;Jet Ski;

Collections:

FirstName  Bill;John

LastName Cobra;Smith

Location   FLA;GA

Owned  House;;Boat;;Condo;;Jet Ski;;

How do I get Owned to be:

Owned  “House;Boat”;”Condo;Jet Ski”

??

thanks

Friday, October 24, 2014 9:58:37 AM

re: Nintex Workflow - Iterate through Related Collections

Hi bcobra,

You can use a Build String action to put those together.

Then if you want to add them to another collection, you can use the Collection Operation action to do an Add.

cheers,

Vadim

Thursday, July 23, 2015 9:47:58 PM
Soni
Gravatar

re: Nintex Workflow - Iterate through Related Collections

Hello guys,

This is for document library, can any one explain me the same scenario for list? Because for list I'm not seeing current item in drop down for xml source.

Thanks,

Soni

Wednesday, July 29, 2015 8:48:01 AM

re: Nintex Workflow - Iterate through Related Collections

Hi Soni,

The Current Item, is because in this post, we're dealing with an InfoPath form and the current item is the form XML.

Are you looking at Querying some XML?  Where is that in the SharePoint List?

cheers,

Vadim

Monday, August 10, 2015 3:38:21 PM
Paulie DeCesare
Gravatar

re: Nintex Workflow - Iterate through Related Collections

Hi Vadim! This post has helped me GREATLY to use a workflow to copy an InfoPath 2010 form and use it in a new workflow (yes, we actually need to do that, lol). So I'm 99% of the way there and so far everything works. At the end of your post you only threw data into a Log and I'm going "ACK! WAIT! I NEED POPULATE THE REPEATING TABLE ON TH NEW FORM!"  ;-)

So I have 5 fields in each row, and I have the 5 collection variables stuffed and I'm using Update XML with an XPath query to //my:formFields/my:CustomerDetail/my:OtherCustomerDetail. Then I selected the "Add child node" radio button and throw the following XML in the box below the radio button, and using the ForEach it all works to populate the FIRST field:

<my:CustomerDetails>
   <my:ipCD_CustKey>{WorkflowVariable:OldAdditionalCustKey}</my:ipCD_CustKey>
</my:CustomerDetails>

So far so good. And I tested the other fields SINGLY just to ensure the Collection Operations did collect the other fields, and they do. So source data is good, and I can create the rows I need in the Repeating table in the new form, and populate ONE of the fields in each row (same field). Where I'm blowing up is trying to populate the remaining fields inside the ForEach. My Update XML has 5 XML Updates to target the 5 fields. At first I left "Add child node" check for EACH update and you can guess what happened: Instead of three rows with all five fields populated (Source form has three rows), I ended up with about 15 rows, each with one specific field populated. So I obviously only want to Add Child ONCE. So then I tried changing the remaining 4 fields to Update Node Value. The workflow published but when I try to open the form, it bombs with NO clear error text telling me what's up.

Hope all this makes sense. I need to populate (update XML) on all 5 fields in eacg repeating row. Can you help me Obiwan? ;-)

Wednesday, August 12, 2015 5:02:31 PM
Paulie DeCesare
Gravatar

re: Nintex Workflow - Iterate through Related Collections

Just to clarify, using an Update XML, I put the XPath to the repeating table:

 

//my:formFields/my:CustomerDetail/my:OtherCustomerDetail

 

In one row is 5 text fields, so I checked Add Child Node and put this in the second box for Selected Node Action:

<my:CustomerDetails>
   <my:ipCD_Customer>{WorkflowVariable:OldAdditionalCustomer}</my:ipCD_Customer>
</my:CustomerDetails>
<my:CustomerDetails>
   <my:ipCD_CustKey>{WorkflowVariable:OldAdditionalCustKey}</my:ipCD_CustKey>
</my:CustomerDetails>
<my:CustomerDetails>
   <my:ipCD_SAPID>{WorkflowVariable:OldAdditionalSAPID}</my:ipCD_SAPID>
</my:CustomerDetails>
<my:CustomerDetails>
   <my:ipCD_Address>{WorkflowVariable:OldAdditionalAddress}</my:ipCD_Address>
</my:CustomerDetails>
<my:CustomerDetails>
   <my:ipCD_City>{WorkflowVariable:OldAdditionalCity}</my:ipCD_City>
</my:CustomerDetails>

All the data populates correctly (in order) but it creates a new row for EACH field. So instead of 1 new row with 5 populated fields, I get 5 new rows each with 1 field populated, in proper order.

 

I tried Add XML Update and making fields 2-5 be part of an Update Node Value, but when it published, the new form won't open, got the famed validation error. I guess I don;t understand XML enough, and what Nintex is doing under the hood. ANYTHING you can throw at this would be joyous. Thanks!

 

 

Wednesday, August 12, 2015 5:25:33 PM
Paulie DeCesare
Gravatar

FIGURED IT OUT

I simply changed the elected Node Action code to:

 

<my:CustomerDetails>
<my:ipCD_Customer>{WorkflowVariable:OldAdditionalCustomer}</my:ipCD_Customer>
<my:ipCD_CustKey>{WorkflowVariable:OldAdditionalCustKey}</my:ipCD_CustKey>
<my:ipCD_SAPID>{WorkflowVariable:OldAdditionalSAPID}</my:ipCD_SAPID>
<my:ipCD_Address>{WorkflowVariable:OldAdditionalAddress}</my:ipCD_Address>
<my:ipCD_City>{WorkflowVariable:OldAdditionalCity}</my:ipCD_City>
</my:CustomerDetails>

That gave me all 5 fields in one row. Now that I see it I feel like a dork, this was an easy one actually, lol. Because I'm adding a new child node I DO end up with a full set of row with a blank at the top and I'm not about to write a conditional statement checkimg if it's the first row or not, the engineer can just delete it if it bugs them, lol. I'm not looping and persisting this data in a database, it's really just FYI data, so as far as I'm concerned. It's good enough.

Posted here to help anyone who gets the same weird request to copy a form. ;-)

Friday, August 14, 2015 7:41:30 AM

re: Nintex Workflow - Iterate through Related Collections

That's awesome. Thanks for sharing that Paulie.

Wednesday, June 8, 2016 2:04:02 AM
Aditya
Gravatar

re: Nintex Workflow - Iterate through Related Collections

Thanks Vadim  for the post .I have "User" and "ID" columns and I need to trigger a mail to each user with the URL that consists of "ID" .Initially I tried nested for each but it was not behaving as  expected but your post has helped me in solving the issue

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?
Register

Statistics

  • Entries (290)
  • Comments (1777)

Categories