I haven't dug through the whole thread and script, but the answer is that it depends on what you have and what you want.
The forEach command takes an array as its last argument. You need to combine the commands units and group to turn your local variable into the array you want.