Skip to main content
Nintex Community Menu Bar

ForEach resets index to 0

  • July 26, 2019
  • 4 replies
  • 25 views

ms7
Forum|alt.badge.img+4
  • I have a ForEach loop that works on a collection of 300+ items.
  • The ForEach will loop through the collection items in batches of 50.
  • The ForEach uses an index variable which increments by 1 on each loop.
  • The ForEach will stop when the variable stop = true.
  • When the index variable is greater than 50 we set the variable stop = true and the ForEach loop is stopped.
  • The ForEach is contained within a Loop. The Loop will loop until the variable loop > 10.
  • When we exit the ForEach we increment the loop variable by 1.
  • The Loop restarts the ForEach.
  • At this point I the value of my index is 51 however when we re-enter the ForEach the index is reset to 0.

 

Can anyone else confirm this behaviour?

4 replies

Simon Muntz
Nintex Partner
Forum|alt.badge.img+23
  • Nintex Partner
  • July 30, 2019
Hi,
This is expected behavior. The Index is set to 0 when starting a For Each action.
I suggest trying to batch in another way.
Do not use the loop and just use the For Each.
In the for each use a "run if" action that looks at the For Each index variable and have it pause every 50 loops for example.

ms7
Forum|alt.badge.img+4
  • Author
  • July 30, 2019

Hi Simon, thanks for replying.

I suspected that this was happening however I feel that this behaviour is incorrect. As I see it the ForEach should use the index variable in a read-only manner. I don't understand why it should be writing to or setting the index variable.

I'll work on an alternative method. Thank you also for the suggestion.


Simon Muntz
Nintex Partner
Forum|alt.badge.img+23
  • Nintex Partner
  • July 30, 2019

The Nintex workflow designer is kind of like a wysiwyg which hides all the programming code.

The code for a loop in most programming languages looks similar to:

for (int i = 0; i < 10; i++)
{
    Do Something
}

As this is the case the variable that keeps track of the loops/index position is always initialised at the start of the loop which means that this is the correct behavior.


ms7
Forum|alt.badge.img+4
  • Author
  • July 31, 2019

@SimonMuntz wrote:

The Nintex workflow designer is kind of like a wysiwyg which hides all the programming code


Yep this is where the wysiwyg of Nintex becomes a challenge :)