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?
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.
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:
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 inputfile.
For this error, Is it possible to show the implementation of For Each ?
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!