Run \foreach\" more than just one time?"

  • 28 February 2017
  • 8 replies
  • 0 views

Badge +3

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 happy.png


8 replies

Userlevel 4
Badge +12

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.

200035_pastedImage_1.png

Does it change the behaviour?

Kind regards,

Enrico

Badge +3

Hello Enrico

Thanks for your respond and the flowers happy.png

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

Userlevel 4
Badge +12

Hmm, it might be an issue in your environment.

I created a similar workflow like you have:

200028_pastedImage_1.png

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:

200029_pastedImage_2.png

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

Badge +3

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.

Userlevel 5
Badge +14

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

Userlevel 4
Badge +12

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.

Badge +3

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...

Badge +3

Now it works!

Thanks to Marian Hatala and‌ ‌ for support.

Regards, Simon

Reply