Branch to action block for each list element

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
jassing
Posts: 94
Joined: 16 Jul 2017 01:42
Location: SF Bay Area

Branch to action block for each list element

Post by jassing » 23 Nov 2019 06:41

Suppose you have a list of phone numbers.
You want to send an sms msg only to numbers that have "55" in it...
How do I branch to an action block for each list element?

for ( number in numberlist ) {
if( contains(number, "55") ) {
// how to branch out to "Send SMS" action?
}
}

Thanks!

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Branch to action block for each list element

Post by Desmanto » 23 Nov 2019 06:58

If you use for() loop, you can't. You must use while() or other if() version.

In this case, you don't have to break out the loop to the send SMS. You simply add all number which have "55" to a new list and then loop SMS to all the number.

Code: Select all

sendnum = newList();
for(number in numberlist)
{
  if(contains(number, "55")
    addElement(sendnum, number)
}
{sendnum} now contains all the number those have "55".

To loop send SMS to all of this, you can use action Send SMS + condition expression. Add a new line script in previous script

Code: Select all

index = 0;
At the action send SMS, use {sendnum[index]} as the number. Then next is expression

Code: Select all

index = index + 1;
index > length(sendnum);
false, loop back to Send SMS. This will now tell send SMS to send to the second number (and so on until finish). True, do nothing, essentially stopping the loop/flow.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
jassing
Posts: 94
Joined: 16 Jul 2017 01:42
Location: SF Bay Area

Re: Branch to action block for each list element

Post by jassing » 24 Nov 2019 03:23

Thanks. I started down that road, but thought there might be a better way.

Thanks! I appreciate the detailed response.

Post Reply