To display the strings as integers (0, 1, 2, 3, etc.) during each iteration of the “For Each” loop in UiPath, you can make use of the loop index. Here’s an updated version of your workflow:
Keep the “For Each” loop with the list of string array variable and the item as currentItem.
Add an integer variable before the “For Each” loop, let’s call it index. Set its initial value to 0.
Inside the loop body, perform the following steps:
Assign the value of index to a new integer variable, let’s call it iterationIndex.
Increment the value of index by 1.At this point, you should have the current string item in the currentItem variable, and the corresponding iteration index in the iterationIndex variable.
Display the iterationIndex variable using the Message Box activity instead of the currentItem variable. This will show the integers (0, 1, 2, 3, etc.) during each iteration of the loop.
you can also try this Create a Output variable for each and change the variable datatype to int32
as the output varaible starts from idex=0 and place a message inside for each it will display all the values like 0,1,2,3 until the items in array was completed…
thanks
My objective is to iterate through a list of string array names and then query them one by one from the entity database and extract an ID for each that will later need to be concatenated into a single string.
The below is where the iteration of numbers should take place. This should be replaced by a variable.
I usually use the repeat number of times activity as I’m more used to it in iteration but for now, I need the For Each.
Please correct me if I’m wrong. In order to match the LocationName with the LocationArray(IterationIndexNumber), you are trying to increment the number like 0,1,2,3 on each iteration, right?
Since you are already iterating through the LocationArray in For Each, you don’t have to access the element like LocationArray(0) or like that. Just try using CurrentItem.ToString.
In that case, instead of assigning an Index outside the loop & trying to tweak it inside the loop again, you can follow this simple step.
Go to the For Each property panel, identify the Index property & create a new variable there. That variable will be a zero based index variable will work perfectly in sync with the iteration.