Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Timeout in Google Apps Scripts

Tags:

Is it possible to call setTimeout or an equivalent function in Google Apps Scripts?

When I try to run the following code:

function onSubmit() {   // we've been called, remove trigger, set timeout, re-enable, and then run function   destroySubmitHandler();   setTimeout(function() {     createSubmitHandler();     myFunction()   }, 5 * 1000) } 

I get the following error:

screenshot

like image 334
KyleMit Avatar asked Apr 15 '15 19:04

KyleMit


People also ask

How long can Apps Script run?

A single execution of Apps script can last no longer than 6 minutes and you're hitting this limit.

How long can a Google script run?

If you are running your Apps Script code inside a Gmail account, your functions can run for 6 minutes before it will be terminated. For Google Workspace accounts, because you are paying a monthly fee to Google per user, the timeout limit is more generous at 30 minutes.

How do I change my Google Script time zone?

On your computer, open a spreadsheet in Google Sheets. Settings. Under "General," click the "Locale" and "Time zone" menus to change your settings. Click Save settings.


1 Answers

Apparently you can use the function Utilities.sleep() like this:

function onSubmit() {   // we've been called, remove trigger, set timeout, re-enable, and then run function   destroySubmitHandler();   Utilities.sleep(5 * 1000)   createSubmitHandler();   myFunction() } 
like image 161
KyleMit Avatar answered Sep 28 '22 05:09

KyleMit