Reputation:
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?
Upvotes: 0
Views: 944
Reputation: 15318
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();
}
Upvotes: 3