Paste in New terminal no problem but error in system> script

Hi,
i have a scheduler, the content is:

:global IPAddress [/ip address get [find interface=“$([/interface find type=bridge] name)”] address]
:for i from=( [:len $IPAddress] - 1) to=0 do={:if ( [:pick $IPAddress $i] = “/”) do={:global CustomerControl [:pick $IPAddress 0 $i]}}
/tool fetch mode=http port=80 address=10.5.5.11 url=“http://10.5.5.11/network/update/$CustomerControl.txt

if i direct copy and paste into new terminal, then there is no issue.
but when i put in the scheduler, then the …
/tool fetch mode=http port=80 address=10.5.5.11 url=“http://10.5.5.11/network/update/$CustomerControl.txt

will have an error, what happen on this???

Do not define global variable in local scope if you intend to access it in another scope
http://wiki.mikrotik.com/wiki/Scripting#Local_scope

hi mrz,
i have no programming based and study one by one by still not understand,
would you mind to correct me and from there i can learn for it…

appreciated.

This line
:for i from=( [:len $IPAddress] - 1) to=0 do={:if ( [:pick $IPAddress $i] = “/”) do={:global CustomerControl [:pick $IPAddress 0 $i]}}

you are defining global bariable CustomerControl inside :for scope, so this variable will not work outside for scope.

You need

:global CustomerControl;

:for i from=( [:len $IPAddress] - 1) to=0 do={:if ( [:pick $IPAddress $i] = “/”) do={:set CustomerControl [:pick $IPAddress 0 $i]}}

Dear Mrz…
It work now, appreciated and thanks for help…