Trigger every 14 days starting on a specific date

ⅰ亾dé卋堺 提交于 2019-12-11 12:28:10

问题


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!');

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 -

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

Can anyone help me?


回答1:


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.

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



来源:https://stackoverflow.com/questions/30561061/trigger-every-14-days-starting-on-a-specific-date

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