我正在尝试创建一个基于时间的触发器来执行我的incrementCell
每年在指定日期的凌晨 1 点永远运行一次。当尝试在下面运行时
ScriptApp.newTrigger("incrementCell").timeBased().atDate(2018, 1, 4).atHour(1).everyWeeks(52).create();
我收到了"Already chosen a specific date time with at() or atDate()."
error.
有趣的是,下面的行不会出错:
ScriptApp.newTrigger("incrementCell").timeBased().atDate(2018, 1, 4).create();
Google Apps 脚本不支持年度触发器,但您可以使用解决方法。创建一个每月 1 日运行的每月触发器,如果该月是一月,则运行实际函数。
function createYearlyTrigger() {
ScriptApp.newTrigger("shouldTriggerRun")
.timeBased().onMonthDay(1).atHour(1).create();
}
function shouldTriggerRun() {
var date = new Date();
if (date.getMonth() === 0) {
incrementCell();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)