[英]2 Time triggers - Google app scripts
i looked at the google app script installable trigger docs online ( https://developers.google.com/apps-script/support ), and one of the examples shows how 2 create 2 time triggers.我在线查看了 google app script installable trigger docs ( https://developers.google.com/apps-script/support ),其中一个示例显示了 2 如何创建 2 个时间触发器。
function createTimeDrivenTriggers() {
// Trigger every 6 hours.
ScriptApp.newTrigger('myFunction')
.timeBased()
.everyHours(6)
.create();
// Trigger every Monday at 09:00.
ScriptApp.newTrigger('myFunction')
.timeBased()
.onWeekDay(ScriptApp.WeekDay.MONDAY)
.atHour(9)
.create();
}
My code:我的代码:
function createTimeDrivenTriggers() {
// Trigger every 1 hours.
ScriptApp.newTrigger('MainFunctionDaily')
.timeBased()
.everyHours(1)
.create();
// Trigger every Friday at 13:00.
ScriptApp.newTrigger('MainFunctionWeekly')
.timeBased()
.onWeekDay(ScriptApp.WeekDay.FRIDAY)
.atHour(13)
.create();
}
However when i try to create the triggers, i get an error:但是,当我尝试创建触发器时,出现错误:
This add-on has created too many time-based triggers in this document for this Google user account此加载项在此文档中为此 Google 用户帐户创建了太多基于时间的触发器
Please advise请指教
UPDATE: The documentation for add-ons was moved.更新:附加组件的文档已移动。 In this case the new location of the below referred restriction is https://developers.google.com/gsuite/add-ons/concepts/editor-triggers
在这种情况下,下面提到的限制的新位置是https://developers.google.com/gsuite/add-ons/concepts/editor-triggers
From https://developers.google.com/apps-script/guides/triggers/installable#limitations (emphasis mine):来自https://developers.google.com/apps-script/guides/triggers/installable#limitations (强调我的):
Limitations
限制
Several limitations apply to installable triggers in add-ons:一些限制适用于附加组件中的可安装触发器:
Each add-on can only have one trigger of each type , per user, per document.
每个附加组件对于每个用户、每个文档的每种类型只能有一个触发器。 For instance, in a given spreadsheet, a given user can only have one edit trigger, although the user could also have a form-submit trigger or a time-driven trigger in the same spreadsheet.
例如,在给定的电子表格中,给定的用户只能有一个编辑触发器,尽管用户在同一个电子表格中也可以有表单提交触发器或时间驱动的触发器。
The alternatives are备选方案是
Two possible issues:两个可能的问题:
You will probably need to choose one of your triggers only but you can try this:您可能只需要选择一个触发器,但您可以试试这个:
function createTimeDrivenTriggers() {
// Trigger every 6 hours.
ScriptApp.newTrigger('myFunction')
.timeBased()
.everyHours(6)
.create();
}
function createTimeDrivenTriggers() {
// Trigger every Monday at 09:00.
ScriptApp.newTrigger('myFunction')
.timeBased()
.onWeekDay(ScriptApp.WeekDay.MONDAY)
.atHour(9)
.create();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.