'Automatically run script on workdays using app script in google sheets
I currently have a function that basically copies values from one tab to another using certain conditions in which i execute daily via menu added in google sheets, how can i create a script that runs on workdays (monday to friday) at 6AM GTM-3 time and calls function copyData () to be executed? I have this code not working:
function createTriggers() {
var days = [ScriptApp.WeekDay.MONDAY, ScriptApp.WeekDay.TUESDAY, ScriptApp.WeekDay.WEDNESDAY, ScriptApp.WeekDay.THURSDAY, ScriptApp.WeekDay.FRIDAY];
for (var i=0; i<days.length; i++) {
ScriptApp.newTrigger(copyData).timeBased().onWeekDay(days[i]) .atHour(6).create();
}
}
Any thoughts?
Solution 1:[1]
Try
function myFunction(){
if (testDate()==true) {copyData()}
}
function testDate(){
var d = new Date();
// not on sunday and saturday
if (d.getDay()!=0 && d.getDay()!=6) {return true} else {return false}
}
Put a daily trigger myFunction
function createTimeDrivenTriggers() {
ScriptApp.newTrigger('myFunction')
.timeBased()
.everyDays(1)
.atHour(6)
.create();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
