For Each
UiPath.Core.Activities.ForEach
Description
Performs an activity or a series of activities, specified in the Body section, on each element of a collection. The elements can be referenced in the activities in the Body section by using the iterator variable, item.
Project compatibility
Windows - Legacy | Windows | Cross-platform
Cross-platform configuration
- In - A collection of items to iterate over. This field supports only
IEnumerablevalues.
Body
- Activities placed inside are executed if the condition is true.
Show additional properties
-
Item name - The name by which to refer to the current item in the iteration. Using a name that describes the item makes it easier to identify.
noteThe value of the In field must be a collection of homogenous objects.
-
Argument type - A dropdown list that enables you to choose what variable type you want to use with the activity.
- Condition - If the condition is true, the Body of the activity is executed.
- Max Iterations - Maximum number of times the activity is executed.
- Index - A zero-based index that specifies which element of the current collection is being iterated, stored in an
Int32variable.
Windows configuration
Designer panel
- In - Specifies the list to iterate through.
Body
- Activities placed inside are executed if the condition is true.
-
Common
- DisplayName - The display name of the body of the activity.
-
Misc
-
Private - If selected, the values of variables and arguments are no longer logged at Verbose level.
-
Properties panel
-
Item name - The name by which to refer to the current item in the iteration. Using a name that describes the item makes it easier to identify.
-
Argument type - A dropdown list that enables you to choose what variable type you want to use with the activity.
- Condition - If the condition is true, the Body of the activity is executed.
- Max Iterations - Maximum number of times the activity is executed.
- Index - A zero-based index that specifies which element of the current collection is being iterated, stored in an
Int32variable.
Windows - Legacy configuration
Designer panel
- ForEach - The name by which to refer to the current item in the iteration. Using a name that describes the item makes it easier to identify.
- In - Specifies the list to be iterated through.
Body
- Activities placed inside are executed if the condition is true.
Properties panel
Common
- DisplayName - The display name of the activity.
Input
- Condition - If the condition is true, the Body of the activity is executed.
- MaxIterations - Maximum number of times the activity is executed.
Misc
- Private - If selected, the values of variables and arguments are no longer logged at Verbose level.
- TypeArgument - A drop-down list that enables you to choose what variable type you want to use with the activity.
- List of items - The variable whose values you want to iterate. This field supports only
IEnumerablevariables.note- When changing the argument type, the content of this activity is deleted.
- The value of the List of items field must be a collection of homogenous objects.
Output
- Index - A zero-based index that specifies which element of the current collection is being iterated, stored in an
Int32variable.
Example of using the For Each Activity
For this example, we use a simple IEnumerable variable comprised of three elements, displaying each of them in a Message Box:
- Create a new Process and drag a For Each activity into the workflow designer.
- From the Variables panel, create a new
IEnumerablevariable, calledListwith the following value:{"one", "two", "three"} - Insert the
Listvariable in the Values property of the For Each activity. - Drag a Message Box activity into the Body section of the For Each activity.
- Insert the
itemiterator variable into the Text property field of the Message Box activity. - Run the file. The For Each activity iterates through each of the values specified in the
Listvariable and displays it in a separate message box.