Why "Break" activity makes execution flow goes out of "for each" when there is "While" or "Do While" nested within "for each" activity? Should it break out of "While" or "Do While", but not all the way out of the outermost "for each."
Issue Description
This error would show up when the "Break" activity is placed in "while" or "do while" of UiPath.System.Activities 19.10 and before: "Activity can only be placed inside a ForEach".
If "while" or "do while" is nested within "for each" activities, the error does not show up. However, it breaks out of "for each" and not "while" or "do while".
The documentation indicates "break" would work with "foreach", "while" or "do while." Read more on Break. However, this is not true in certain conditions.
There are 2 types of "while" and "do while" activities. The current documentation is true for the latter one.
- The one comes with UiPath.System.Activities 19.10 and before, which has the internal name of System.Activities.Statements.dowhile (in case of "do while")
- The one comes with UiPath.System.Activities 20.4 and later, which has the internal name of UiPath.Core.Activities.InterruptibleDoWhile (in case of "do while")
Resolution
This change has been documented in the Release Notes UiPath v23.4.2: System Activities: New Features And Improvements 6.
In UiPath.System.Activities 19.10 and before, the "break" activity only works with "for each" activity. It would not break "while" or "do while" generated out of 19.10 version. Note that if "while" or "do while" activities had been added out of UiPath.System.Activities 19.10, they will have this limitation even after the UiPath.System.Activities is updated to 20.4 or later.
When "break" activity has to be placed inside of "while" or "do while," the UiPath.System.Activities have to be updated to 20.4 or later and the activities have to be recreated.
The types of "while" and "do while" activities can be found by checking the internal name shown in the properties. Here are the examples:
- 19.10 or before
- 20.4 and later
Root Cause
UiPath.System.Activities 19.10 or before directly utilize the DoWhile Class in .Net when Do While activity is used. Read more on DoWhile Class information.
Packages 20.4 and later have a "wrapping" method that appears and that is UiPath.Core.Activities.InterruptibleDoWhile.
While creating a simpler workflow test with just a single do while and a break activity in 19.10, here is the result: "Activity can only be placed inside a ForEach".
This indicates "break" would not work with "do while" or "while" in the 19.10 pkg. However, the documentation says break would work with foreach, while or do while. Read more on Break .
Here is the assumption.
- In versions 19.10 and before, "break" activity only worked with "foreach." Older document may have mentioned that, but that cannot be confirmed at this point.
- A newer version of loop activities like UiPath.Core.Activities.InterruptibleDoWhile had been added at 20.4, and it started supporting "break" activity.
Therefore, the current document says "break" is supported by while and do while.