You could either check if there's one with "find count-only" being different from 0, or you could use "do {} on-error". I don't know which is more efficient, but purely on the basis of "cleanness", I think the "find count-only" way is better.
To minimize the menu changeups, the menu could be moved on top, and ":" being used on the queues, so...
/ip firewall address-list
:local listName "List"
:foreach i in=[:queue simple print as-value] do={
:foreach j in=($i->"target") do={
:if ([find count-only where list=$listName && address=$j] = 0) {
add list=$listName address=$j
}
}
}
Besides, one note if someone else try to use it... for the script you wrote to work in
RouterOS 5.x it needs a small modification in the second line. It should be like this:
5.x doesn't support associative arrays, so that won't work there at all. It only has non-associative arrays, where you needed to know the position of each property value to use it (with :pick), and you hoped MikroTik would not modify it in the next release (which I don't know if they did, as I'd never used scripts on queues myself back then) OR what most people did is what you did in your first post - use print to find the item's number, then do a separate "get" for each of its properties. Much less efficient, but far more stable between versions.