ExitForEach Use Examples
Basic Use Example
In this example, we query to find all the items in the cart. We then ForEach on the results. Each iteration checks how many items are in the cart so far. If at any point we reach the limit of items per cart, we exit the ForEach and return a message to the user that the items cannot be added to the cart.
When the ExitForEach runs, the service output returns a True/False flag indicating the exit as successful or failed as well as the index that it was on when the exit occurred.
Not Exiting the ForEach Loop
Exiting the for each loop if you do not wish to continue it, is good practice, but not always necessary. The example below iterates through all the results of GetUserId, but when it finds the correct one, it shows a message to the user with SetWindowsAttributes. Since the process is ending once it finds the match, there will never be an issue where WorkData/GetUserId is referenced again, but EASYProcess is referencing that node with an index: WorkData/GetUserId.
The ExitForEach could still be used here to uphold good development practices. That way, when future developers make changes to the process, it is possible that they could try to reference WorkData/GetUserId and have undesired results when indexing is still occurring.