This add-on has created too many time-based triggers in this document for this Google user account

时间:2017-04-10 00:40:03

标签: google-apps-script triggers google-sheets google-spreadsheet-api

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();

2 个答案:

答案 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)

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.

enter image description here