I have a GAS time based trigger that I would like to run at intervals of some combination of hours and minutes (i.e. the triggered function would run every 2 hours and 30 minutes, or every 4 hours and 15 minutes). So I am chaining the everHours and everyMinutes methods together and passing in values. However, Google Apps Script doesn't like this and I keep getting the following error:
Exception: The recurrence interval on the clock trigger has already been set.
This error occurs at the line containing the everyMinutes()
method in the code below.
Is it not possible to chain these two methods? The GAS class ClockTriggerBuilder documentation doesn't explicitly say you can't chain them, but the error appears to indicate that you can't.
If Google Apps Script doesn't allow you to chain the everyHours() and everyMinutes() methods, is there some kind of a work around that would achieve a similar result? Perhaps chaining the everyHours() and nearMinute() methods?
The trigger this function runs sends data rows ("leads") to other spreadsheets ("clients"). Once all the leads have been sent for a day, another function kills this trigger, and then resets the trigger for the next day. I would like a different time interval to be passed for the following day.
Here is my code:
function createLeadTrigger(){
let hours = 1
let minutes = 15
Logger.log(`For today, leads will be sent to clients every ${hours} hours and ${minutes} minutes.`)
ScriptApp.newTrigger('sendALeadToEachClient')
.timeBased()
.everyHours(hours)
.everyMinutes(minutes)
.create();
}