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

ぃ、小莉子 提交于 2019-12-11 04:07:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!