Community discussions

MikroTik App
 
AASHS
just joined
Topic Author
Posts: 1
Joined: Sun Dec 24, 2023 9:09 pm

Foreach Problem

Fri Jan 26, 2024 8:46 pm

Hello all,
I need help
I write the script for send text to telegram
the text is output from foreach
but i have a problem
the text success to send to my bot on telegram but the value is corrupt

the output just send to my bot just one line
acctually output is 3 line
how to fix my problem?

this is my script
#Print UserOFF#
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
:local offuser;
:foreach i in=[/system sch find where comment=offuser] do={
:local useroff ([/system sch get $i name]);
:set offuser ($useroff);
/tool fetch url="https://api.telegram.org/bot$bot/sendme ... t=$useroff
}
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------#

this is output from foreach

:local offuser; :foreach i in=[/system sch find where comment=offuser] do={ :local useroff ([/system sch get $i name]); :set offuser ($useroff); :put $offuser};
ida@sm.net
adi@sm.net
dai@sm.net


the bot ust received text one line
ida@sm.net

Note : adi@sm.net and dai@sm.net not send to my bot

i want to send the text like this to my bot

1. ida@sm.net
2. adi@sm.net
3. dai@sm.net
 
optio
Long time Member
Long time Member
Posts: 675
Joined: Mon Dec 26, 2022 2:57 pm

Re: Foreach Problem

Sat Jan 27, 2024 6:55 pm

try with in loop:
/tool/fetch url="https://api.telegram.org/bot$bot/sendmessage%5C?chat_id=$chat&text=$useroff" output=none as-value

Who is online

Users browsing this forum: No registered users and 6 guests