Create Time Trigger With Google Script And Spreadsheet

I want to create a simple time trigger for my worksheet using Google Script, everything described in the docs , but when I call the function I get the error:

Google Apps: You do not have permission to call newTrigger

      

I am trying to find a solution on the internet, but I got no results. Can anyone help me? Thank!

PS My code:

 ScriptApp.newTrigger("consolius")
   .timeBased()
   .everyMinutes(1)
   .create();

function consolius() {
   SpreadsheetApp.getUi().alert('Hello, world!');
}

      

+3


source to share


1 answer


The limitations mentioned in the comments are not specific to your use case, they are for add-ons only . Right information is located here .

But even if you can actually create a timer trigger to run the function every minute, you won't be able to use the method you are trying as the timer trigger cannot communicate with the Ui.

If you look at the error notification, you will see this message:



Details:
Start   Function            Error Message                                            Trigger    End
7/3/15 4:08 PM  consolius   Cannot call SpreadsheetApp.getUi() from this context. (line 26, file "clean sheet") time-based  7/3/15 4:08 PM

      

Another interesting topic: you have to include a script that creates the trigger in the function, otherwise you will create a new trigger every time ANY other function in this project is run , including the function that triggers calls, it gets pretty messy quickly! (whatever is "global" is executed every time any function is called).

Last but not least, you cannot use code like this in a custom function, it must be in a script that you run from a menu or button.

+2


source







All Articles