skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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:

    /** Initial set up for creating triggers */
    function setUpTriggers(){
      ScriptApp.newTrigger("unchEcked").timeBased().atHour(23).nearMinute(50).everyDays(1).create();
      ScriptApp.newTrigger("chEcked").timeBased().atHour(18).nearMinute(50).everyDays(1).create();
    }
    

    Delete all existing triggers at https://script.google.com before running this function exactly once.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search