cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Run "foreach" more than just one time?

Jump to solution

Hello Community

Question:
Is it possible to run a "foreach" in a statemachine more than just one time?

Problem:
When the workflow runs "correct" (happy path) the "foreach" runs once (red arrows):

State 1 -> State 2 -> State 4

Now if we take the blue arrow path, the "foreach" does not process the collection a second time, the "foreach" will skiped.

Can someone tell me what is the problem?

State 1 -> State 2 (foreach run) -> State 3 -> State 1 (get all items again) -> State 2 (foreach will skipped) -> ...

Hopefully I explained it clearly

Labels: (1)
Tags (2)
0 Kudos
Reply
8 Replies
Workflow Hero

Re: Run "foreach" more than just one time?

Jump to solution

Hello,

first, awesome illustration. I always wondered how to illustrate such questions but this one was easy to understand and to follow. Will keep this in mind.

Second, in general the for each should run through the collection every time. You could try to clear it before you go into the list query the second time.

Does it change the behaviour?

Kind regards,

Enrico

0 Kudos
Reply
Workflow Hero

Re: Run "foreach" more than just one time?

Jump to solution

Hello Enrico

Thanks for your respond and the flowers

I allready implemented this option (delete the actuall collection befor change the state), sadly this does not work.

0 Kudos
Reply
Workflow Hero

Re: Run "foreach" more than just one time?

Jump to solution

Hmm, it might be an issue in your environment.

I created a similar workflow like you have:

I query a list that has 4 elements and iterate through the collection, writing the ID of those elements to workflow log.

If I reject the task in State 2, it goes back to State 1 and does everything again.

In workflow log I can see that the collection was iterated twice:

Can you check if you have the latest build version of Nintex Workflow installed? Maybe there was a problem in an older version. You should have version 3.2.1.0 installed but in my version it works too (3.2.0.0).

Kind regards,

Enrico

Reply
Workflow Hero

Re: Run "foreach" more than just one time?

Jump to solution

We have installed the version 3.2.1.0

My log looks like this:

The collection will filled again, but not processed by the "foreach". its goes direct to the state with the flexi task.

But, in your sample it works, so the error is on my side.

0 Kudos
Reply
Workflow Hero

Re: Run "foreach" more than just one time?

Jump to solution

do you have any stop condition configured in for each loop, that could cause to skip the loop in second turn?

Reply
Workflow Hero

Re: Run "foreach" more than just one time?

Jump to solution

What might help is exporting the query list action and the loop operation into a second workflow and start that workflow from your state machine, but I wonder why it is not working in the first place.

0 Kudos
Reply
Workflow Hero

Re: Run "foreach" more than just one time?

Jump to solution

Yes I have. This could be the reason, I will check this. There's a Yes/No Variable, I should set this variable back to the initial value...

Reply
Workflow Hero

Re: Run "foreach" more than just one time?

Jump to solution

Now it works!

Thanks to Marian Hatala and‌ ‌ for support.

Regards, Simon

Reply