此加载项在此文档中为此Google用户帐户创建了太多基于时间的触发器 [英] This add-on has created too many time-based triggers in this document for this Google user account

查看:81
本文介绍了此加载项在此文档中为此Google用户帐户创建了太多基于时间的触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到标题中的错误-该插件在此文档中为此Google用户帐户创建了太多基于时间的触发器

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

当我运行

该附件用于创建时间触发器。我已经在3个文档中一起创建了7个触发器。

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

ScriptApp.newTrigger("function") .timeBased() .atHour(5) .everyDays(1) .create();

推荐答案

在调用创建新触发器的函数时,最好删除同一触发器的所有现有触发器相同功能内的名称。否则,每次运行该函数时,您可能最终都会创建一个新触发器。

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;
  } 

}

这篇关于此加载项在此文档中为此Google用户帐户创建了太多基于时间的触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆