I have a tool that I have created with Google docs, part of it is that I back up a set of numbers on a daily basis at 11am which I use to create a chart to show progress over time. I have this script running using a trigger that is set to backup the data once a week.
What I would really like to do is only back this data up on weekdays as the weekend data is throwing my averages out. So just Monday - Friday daily at 11am
Does anyone have a way of doing setting the script to run this way programatically?
onEdit(e) The onEdit(e) trigger runs automatically when a user changes the value of any cell in a spreadsheet. Most onEdit(e) triggers use the information in the event object to respond appropriately. For example, the onEdit(e) function below sets a comment on the cell that records the last time it was edited.
I had the same idea as Zig Mandel.
Instead of creating 1 trigger for each day, a simpler method is to stop the function if it is the week-end.
Set the trigger to Daily
and add few lines of code at the beginning of the function to do the trick:
function functionName(parameters) {
//Skip week-end
var day = new Date();
if (day.getDay()>5 || day.getDay()==0) {
return;
}
//Code to be executed
}
You can use the following function to create Triggers that will run every weekday at 11 AM.
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("your_function_name")
.timeBased().onWeekDay(days[i])
.atHour(11).create();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With