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();
答案 0 :(得分:3)
当调用创建新触发器的函数时,最好删除同一函数中同名的所有现有触发器。否则,每次运行该功能时,最终都可能会创建一个新的触发器。
另一个不错的选择是检查现有触发器并仅在不存在时创建新触发器。
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;
}
}
答案 1 :(得分:0)