Reputation: 1
Would it be possible in GoogleScripts to execute a function at different times, with the same trigger?
I think this would be possible if time-driven triggers would support multiple parameters, but I don't know if it's the case.
For example would this work?
function createTimeDrivenTriggers() {
ScriptApp.newTrigger('myFunction')
.timeBased()
.onWeekDay(ScriptApp.WeekDay.MONDAY; ScriptApp.WeekDay.TUESDAY;)
.atHour(9; 10;)
.create();
}
I have a set of 10 links that need to be copied from one sheet to another, at different times. For example I have:
Link A that needs to be copied on Monday at 3 and 7, and on Tuesdays at 2 and 5. The other links follow the same pattern.
I was thinking of having a trigger for each function, but I would need the trigger to be handle more than one parameter.
If the above is not possible, what would be the optimal solution for something like this?
Best regards,
Thurstan
Upvotes: 0
Views: 48
Reputation: 11278
You can create a trigger that runs hourly and then add the logic inside the trigger function.
function myFunction() {
var date = new Date();
// Monday
if (date.getDay() === 1) {
if (date.getHours() === 9 || date.getHours() === 10) {
// do something
}
}
}
Upvotes: 1