I am very new to Javascript and google apps but slowly finding my feet (with help)
I've written a script that does various things, one part of this script, is installing a trigger. Here it is.
function setTrigger() {
var ss = SpreadsheetApp.getActive();
var triggers = ScriptApp.getProjectTriggers();
Logger.log('Amount of triggers ' +triggers.length);
var j = 0;
for (var i = 0 ; i < triggers.length;i++){
if(triggers[i].getHandlerFunction() == 'getNotes' ){j++;}
}
Logger.log('Amount of matching triggers ' +j);
if(j == 0 ){ScriptApp.newTrigger("getNotes").forSpreadsheet(ss).onFormSubmit().create();}
}
Here is the problem I'm having.
The above code is called in the onOpen()
trigger.
When I open the sheet, and check logs, my trigger isn't installed and I get the following message.
Execution failed: You do not have permission to call getProjectTriggers
When I run the onOpen()
manually. The trigger is installed.
I currently own the spreadsheet, but ideally, i'd like to share it with people and the trigger installs and works.
Any ideas?
Following your comment :
Change the name of your function to anything else and create an installable trigger that runs this function on SS open, as mentioned in the doc, simple triggers can't do anything that requires authorization but installable ones do.
Edit : complete example with your code
After saving this in a spreadsheet and setting manually a trigger on open with the specialonOpen function (and accepting the authorization request), I refreshed the browser and get it working with your menu and the new trigger as well (see illustration below -in french because I used another gmail account with old spreadsheet version, my english one has new version and onFormSubmit doesn't work in new versions)
EDIT 2 : a solution with a Browser message to suggest install from a menu.