terminating a running script from another script

Hi there,

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??

Thanks

checking a condition inside the loop is THE way to go

ok thanks! great!

faheemhameed:
Hi there,

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??

Thanks

Great tip! Never thought of that! Thanks! :D

you are welcome!! :)

Hi faheemhameed,

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.

Please shine your light! :idea: :)

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");
}

stop broadcast script

globals.stopBroadcast = 1;

Cheers