I guess it fails since you try to use ID on an interface. ID change may change when some connects/disconnects etc.
So You need to use the find function.
Here is an example on my script to get the signal strengt from all user connected.
:do {
:if ([:len [/interface wireless find ]]>0) do={
:foreach logline in=[/interface wireless registration-table find] do={
:local output "$[/interface wireless registration-table print as-value from=$logline]"
:set ( "$output"->"script" ) "wifi"
:log info message="$output"
}
}
} on-error={}
Script is part of my Splunk monitoring solution found here:
http://forum.mikrotik.com/t/tool-using-splunk-to-analyse-mikrotik-logs-3-3-graphing-everything/121810/1