问题
I have a weird problem. I am trying to understand how this trigger function actually works in Gapps: getUserTriggers() https://developers.google.com/apps-script/reference/script/script-app#getusertriggersspreadsheet
I am using this very simple piece of code used as script within a spreadsheet:
function testing(){
var ss = SpreadsheetApp.openById('some id');
var triggers = ScriptApp.getUserTriggers(ss);
// Log the event type for the first trigger in the array.
Logger.log(triggers[0].getHandlerFunction())
}
At the same time, I have manually scheduled this function to run every hour and I see it on the list of "My Triggers" under https://script.google.com/u/0/home/triggers. Everything is done from 1 account (script creation, script scheduling)
The thing is that when I run the function, it returns 0 items in the array and I would expect 1 item in the array - the trigger which I've created manually and the one which I see in https://script.google.com/u/0/home/triggers for this file.
So the question is - how come I am getting 0 items and not 1 item?
All I'm getting is "TypeError: Cannot read property 'getHandlerFunction' of undefined (line 5, file "Code")"
DZ
回答1:
As written in the documentation,
Gets all installable triggers owned by this user in the given spreadsheet, for this script or add-on only
It only returns triggers for the Spreadsheet, i.e., triggers based on Spreadsheet Trigger Builder: like edit , open.
For other triggers, use getProjectTriggers() instead.
来源:https://stackoverflow.com/questions/63713929/getusertriggers-returns-empty-array-even-though-trigger-exists