ForEach ... a basic question

Short version : do I need to fiddle with the Type of the ‘item’ var in a ForEach ?

Context :
In a var “mijnProcessen” I collect all running processes in my session using a GetProcesses activity.
So I ctrl-K into its var field and invent a varname, and I automatically get a Type ‘List of Processes’ back. Looking good !

But then I want to iterate over that var, so I pick a ForEach activity: the easy part is retyping the List variable. But then trouble begins : the item var that came with the ForEach does not infer that it should be of type Process. In the body of the loop I can not intellisense this : item.processname.tostring

Then I start fiddling with the ‘item’ var, replace it with a var of type “Process” and scope “body”. The compiler stops complaining at that point, but @runtime it throws “object reference not set to an instance of object”

I worked around it by using while loops with an index, but I need to get past this problem once and for all. What did I skip when reading about uipath’s foreach ?


Solved it :

This is wrong :
foreach item in myProcesses

This is the correct way :
foreach p in myProcesses

without quotes obviously, this webeditor is quirky

item.ProcessName should work cause that’s what I use.
Make sure your ForEach has the correct TypeArgument

The “item” or “p” in your examples both would work. The first box after ForEach is just the name of the variable you want. You can name the variable anything you want as long as it isn’t a reserved word

If you don’t touch it it says Object there. I tweaked it before, but never tried the base type as I expected inference would work, instead using “List of base type”. Thanks for clearing this up.