I would like to make a function about 'Add an Approver', so I add a 'State machine' inside a 'For each' loop, but the loop will not end. No matter how many times I choose approve, it will go back to the start of loop. If I remove the 'State machine', it is OK.
Please someone help me.
Solved! Go to Solution.
It's always a best practice to have each logical branch in a state machine to end with a Change State action. In order for the State Machine to end properly, it needs to go through a Change State action with a value of "End State Machine" value at some point. Also it's best practice to use a Change State action with a value of "End State Machine" value instead of an "End Workflow" action in the State Machine.
Your Approve branch in the "Assign Flexi Task" action does not have a Change State action. Try that and see what happens.
So there are two things to consider:
1) The state machine is itself a looping mechanism. Without an End State action the state machine will continue to loop.
2) Assign Flexi task will pause until the task is complete. You may perceive this as Endless looping, but really the workflow is just waiting until the first Assign Flexi task is completed, before doing your next "For Each" iteration. Did you mean for the For Each to assign out a bunch of tasks consecutively without waiting on the previous approval to occur? If so you will need to tweak the design.