Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop a google app script from an infinite loop always executed when opening the Google Spreadsheet document?

I was trying to implement an improved solution of the google script suggested here: Google Spreadsheet: Script to Change Row Color when a cell changes text;.

However, after debugging my script, it occurred that my document is not accessible anymore. It seems that my script is erroneous and prevents my document from opening... The consequence is that I cannot disable/edit/remove the associated google script and I am stuck!

Do you have a way to solve this blocking issue?

Thanks,

Fabien

UPDATE: After further investigations, it seems that the reason of the problem is due to an infinite loop script called from the event trigger onOpen(). So my question can be reformulated to:

How do you stop a Google App script that gets into an infinite loop?

Can I use another script to kill the execution of this erroneous script ?

like image 641
fabien7474 Avatar asked Feb 15 '13 10:02

fabien7474


People also ask

How do I stop Google App script from running?

If you are in the code editor, and want to stop a script from running, you can click the "cancel" link in the toast display. Or you can click "View" -> "Executions" from the code editor and then terminate the script.

How do I debug an app script in Google Sheets?

To run the script in debug mode, at the top of the editor click Debug. Before the script runs the line with the breakpoint it pauses and displays a table of debug information. You can use this table to inspect data like the values of parameters and the information stored in objects.


2 Answers

This is an old post but just in case:

Go to your Google Apps Script project page, within the My Executions tab: https://script.google.com/home/executions.

Filter by status so you can find the running project. On the right you have the three dots menu where you can terminate the running project.

like image 96
lordofmax Avatar answered Sep 23 '22 20:09

lordofmax


Actually it is very simple. In your script loop, set a global var. Then when you want to stop it, wire up a script to set global var to false to a button image for example. Like this:

var RUNLOOP = true;

function YourLoop() {
  if (RUNLOOP) {
     // your code that does something every loop
  }
}

function stopLoop() {
  RUNLOOP = false;
}
like image 31
GeneCode Avatar answered Sep 20 '22 20:09

GeneCode