How could I terminate a looping script from another script?
I have a script which loops through contact records and sends emails to each of them. If I decide to stop the email sending, I click the stop button.
Currently I have a global variable globals.stopEmail set to 1 in the stop button method. In the looping method the variable is checked for the value 1 to issue a break statement that ends the loop. It seems to work fine. But I wonder this is the exact method to do it or we have a special function to stop any other scripts running??
How could I terminate a looping script from another script?
I have a script which loops through contact records and sends emails to each of them. If I decide to stop the email sending, I click the stop button.
Currently I have a global variable globals.stopEmail set to 1 in the stop button method. In the looping method the variable is checked for the value 1 to issue a break statement that ends the loop. It seems to work fine. But I wonder this is the exact method to do it or we have a special function to stop any other scripts running??
I looked a little bit further into this tip.
How are you doing this? When I start a loop in a client, my client is not accessable during the loop. So I can’t push a button which sets the global.
This is quite simple. I am not sure why it is working for you. It works fine for me in developer and client mode. Please see the excerpt from my email broadcast sending script.
broadcast sending script
globals.stopBroadcast = 0;
for (var i=1; i <= maxRecords; i++) { //******* FOR LOOP 1
if (globals.stopBroadcast == 1) {
break;
}
email sending scripts go here ...
} //******* FOR LOOP 1
if (globals.stopBroadcast == 1) {
plugins.dialogs.showErrorDialog( "", "email sending has been terminated");
}