问题
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