Below script was working fine yesterday, and today I have got an error:
Exception: This script has too many triggers. Triggers must be deleted from the script before more can be added.
function chEcked() {
SpreadsheetApp.getActive().getSheetByName('To-do').getRange("F1").setValue(true);
SpreadsheetApp.getActive().getSheetByName('OverDate').getRange("F1").setValue(true);
}
function unchEcked() {
SpreadsheetApp.getActive().getSheetByName('To-do').getRange("F1").setValue(false);
SpreadsheetApp.getActive().getSheetByName('OverDate').getRange("F1").setValue(true);
}
ScriptApp.newTrigger("unchEcked").timeBased().atHour(23).nearMinute(50).everyDays(1).create();
ScriptApp.newTrigger("chEcked").timeBased().atHour(18).nearMinute(50).everyDays(1).create();
What I want to do is have this script run every day at a specific time.
I know if I delete the old trigger, the script will execute successfully, but I can’t do it manually every day.
Would you modify the script to meet my need?
2
Answers
Instead of adding the trigger programmatically, I would add the trigger through the Apps Script project interface menu for triggers. You can use the menu to schedule as you need.
Your create trigger is outside any function and runs every time, any script is run. Put it inside a function and run it only once:
Delete all existing triggers at https://script.google.com before running this function exactly once.