cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Nintex Newbie

ForEach resets index to 0

Jump to solution
  • 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?

Labels: (1)
0 Kudos
Reply
4 Replies
Highlighted
Nintex Employee
Nintex Employee

Re: ForEach resets index to 0

Jump to solution
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.
Reply
Highlighted
Nintex Newbie

Re: ForEach resets index to 0

Jump to solution

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.

0 Kudos
Reply
Highlighted
Nintex Employee
Nintex Employee

Re: ForEach resets index to 0

Jump to solution

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.

View solution in original post

Reply
Highlighted
Nintex Newbie

Re: ForEach resets index to 0

Jump to solution

@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 :)

0 Kudos
Reply