I am new to writing some scripts. I have this function right here, that i created. It always comes with an interval of 2 hours. Everytime, that the trigger was used, it gets disabled. I have to delete them and start them again. Is there a way to re-enable the scripts, or to delete and recreate them daily?
They always have to come at the certain time.
I used the script below:
function setTriggerNL() {
var startTime = new Date();
startTime.setHours(7); //Allows to set a preferable time to start
startTime.setMinutes(45);
startTime.setSeconds(0);
var endTime = new Date();
endTime.setHours(23); //Allows to set a preferable time to end
endTime.setMinutes(45);
endTime.setSeconds(0);
var intervalMinutes = 120; //Works with a 120 Minutes interval
var currentTime = new Date();
var nextRunTime = new Date();
nextRunTime.setTime(Math.ceil(currentTime.getTime() / (intervalMinutes * 60 * 1000)) * (intervalMinutes * 60 * 1000));
if (nextRunTime < startTime) {
nextRunTime = startTime;
}
while (nextRunTime <= endTime) {
ScriptApp.newTrigger('NewsletterHTML')
.timeBased()
.at(nextRunTime)
.create();
nextRunTime.setTime(nextRunTime.getTime() + (intervalMinutes * 60 * 1000));
}
}
New contributor
Timo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.