从特定日期开始每14天触发一次 [英] Trigger every 14 days starting on a specific date

查看:134
本文介绍了从特定日期开始每14天触发一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Google表格中触发一个电子表格来每14天重置一次,但我需要它在某个日期开始这样做(对于公司时间表而言并非如此)。这是我的工作,每14天触发一次......

I'm trying to trigger a spreadsheet in google sheets to reset itself every 14 days but I need it to start doing that on a certain date (it's for company time sheets not that that's relevant). Here's what I have that works, triggering every 14 days...

function test() {

ScriptApp.newTrigger("14day_trigger")
   .timeBased()
   .everyDays(14)

Browser.msgBox('Testing!');

我想开始14天的周期2015,06,12。我试着用.atDate .. 。

I want to start the 14 day cycle 2015, 06, 12. I tried with .atDate ...

function test() {

ScriptApp.newTrigger("14day_trigger")
   .timeBased()
   .atDate(2015, 06, 12) 
   .everyDays(14)

Browser.msgBox('Testing!');

但是这会产生错误 -

But this gives the error -


已经使用at()或atDate()选择了特定的日期时间。

Already chosen a specific date time with at() or atDate().

任何人都可以帮助我吗?

Can anyone help me?

推荐答案

创建三个函数:

Create three functions:

function triggerAtDate() {
  ScriptApp.newTrigger("atDateTrigger")
    .timeBased()
    .atDate(2015, 06, 12)
    .create();
};

function 14day_trigger() {
  ScriptApp.newTrigger('resetItself')
    .timeBased()
    .everyDays(14)
    .create();
};

function resetItself() {
  SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].clearContents();
};

然后在脚本编辑器中运行第一个函数。一旦 一次触发器 运行完毕,就不再需要了,您可以将其删除。

Then run the first function inside of the script editor. Once the one time trigger has run, it is no longer needed, you could delete it.

您可以等待您想让触发器运行的那一天,然后在当天手动创建14天触发器。

You could wait for the day that you want the trigger to run from, then manually create the 14 day trigger on that day.

这篇关于从特定日期开始每14天触发一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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