问题
I get the error as in title - This add-on has created too many time-based triggers in this document for this Google user account
When I run the add-on.
The add-on is for creating time triggers. I have created together of 7 triggers in 3 documents.
Now I can't create new trigger in any documents.
ScriptApp.newTrigger("function") .timeBased() .atHour(5) .everyDays(1) .create();
回答1:
When calling a function that creates a new trigger, it is always a good idea to delete all the existing triggers of the same name inside that same function. You may otherwise end up creating a new trigger each time you run that function.
The other good option is to check for existing trigger and create a new trigger only if none exist.
function createTrigger(fnName) {
var triggers = ScriptApp.getProjectTriggers();
var triggerExists = false;
for (var i = 0; i < triggers.length; i++) {
if (triggers[i].getHandlerFunction() === fnName) {
triggerExists = true;
break;
}
}
if (!triggerExists) {
ScriptApp.newTrigger(fnName).timebased().everyHours(1).create;
}
}
回答2:
You should only have to run that once to create the trigger. In script editor, go to Edit>All your triggers and you should see all of the triggers for your script. You will see multiple identical triggers created from that newTrigger function. Delete all the duplicates.
来源:https://stackoverflow.com/questions/43313445/this-add-on-has-created-too-many-time-based-triggers-in-this-document-for-this-g