I’m using UiPath Studio 2022.12.0 and can’t figure out the For Each. I think it changed?
I have a System.Collections.Generic.List(Of String) and I’ve added 4 strings to the list. Now I want to loop through the list using a For Each to get process each string value. Once I’m in the For Each, how to I access the specific list item?
you can change the TypeArgument property to String and the just call the Item or CurrenItem variable in your Write line
if you want your for each as object, in your write your pass
Item o currenItem will depends on your for each
Ah yes. There in lies the problem. In your For Each activity, you can specify the type argument, etc. Take a closer look at mine:
The above is just a test file I’m using for debugging. In my actual process, I’m getting the following error message when it hits the For Each:
For Each: Unable to cast object of type ‘System.String’ to type ‘System.Collections.Generic.List`1[System.String]’.
I’m so confused…
As per the latest UiPath update, for the For Each activity, you don’t have to specify the TypeArgument manually. The system will automatically detect the type of the data that you are iterating through & will continue as per.
Hope this helps,
That’s all well and good, but how to I access the list item within the loop?
Are you in the latest system.activities package version?
I have to use UiPath.System.Activities V 22.4.1 (long story…)
Hi @carlor ,
Is it possible for you to share the Screenshot of the dependencies and their versions used ?
Here is my sandbox version where I’m trying to just access the list item:
I’m using the same versions in my actual process:
Could you just Press the keys
Ctrl+Space inside the
Write Line activity and check if you can find a variable with name
Maybe also check if a variable named
item is present.
Maybe more detailed from the activity :
Give a try using the following code in your write line activity
As same as the default type argument, this version stores the iterational data in a default variable called item
So inside the loop, you access the current loop item using:
Hope this helps,
Ok. So, in my sandbox process, “item” does the trick. I’m now able to iterate through the items in the list. Now I know that it’s possible Thank you!
Now it just leaves me with trying to figure out why it won’t work in my “real” process. In a library we created, we pass in the List(Of String) and have a For Each loop. Now, this is where it gets confusing for me. Within the For Each, I don’t have an “item” variable. The developer that wrote the library is using “inputfile.ToString”. I don’t know how/where he got that as it isn’t declared anywhere and it’s only appears once. (Unfortunately I can’t ask him has he is out of the country right now.)
At this point, the inputfile variable doesn’t matter because when I try to run I get an error as soon as it hits the For Each:
Unable to cast object of type ‘System.String’ to type ‘System.Collections.Generic.List`1[System.String]’.
In the library that processes the list, it is an argument defined as:
These are the dependencies in the library:
The library that creates the list uses the following dependencies:
and the main process that uses the two libraries has the following dependencies:
The List variable passed around is defined the same way everywhere.
Most probably the System Activities version that the other person has used to develop the workflow was not in the same version as that you have now (Latest Stable). In the previous versions, we could rename the iterative variable from the For Each activity, and this maybe the reason that the
item is now
For this error, Is it possible to show the implementation of
For Each ?
Winner! Winner! Chicken Dinner!
Thank you Superman! Mentioning the different versions hit on something. We’ve had to downgrade the original dependencies we were using and I guess that’s where things went haywire. I dragged over a new For Each, moved the contents of the original and renamed the variable to item.ToString and it worked!
Thank you thank you thank you!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.