Add-on Trigger 不是 运行,我该如何解决

Add-on Trigger not running, how can I troubleshoot

我的插件创建了一个每小时 运行 的触发器。当我从脚本中 运行 它时它可以工作,但是当作为附加组件发布时它似乎不起作用。我想知道解决此问题的最佳方法是什么。

下面是运行整点的脚本。也许那里有一些东西可以帮助弄清楚发生了什么。

function updateDay(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = ss.getSheets(); 

  for (i in sheets){
    var sheetName = sheets[i].getName();
    var cella2 = sheets[i].getRange(1, 2).getValue();
    if (sheetName == cella2){

      //check if weekend
      var cellA3 =  new Date(sheets[i].getRange(3, 1).getValue());
      if (cellA3 == "-"){
        sheets[i].deleteRow(3);
        SpreadsheetApp.flush();
        cellA3 =  new Date(sheets[i].getRange(3, 1).getValue());
      }

      var cellA3F = Utilities.formatDate(cellA3, "EST", "MM/dd/yyyy");
      var today = new Date();
      var todayF = Utilities.formatDate(today, "EST", "MM/dd/yyyy");

      if (cellA3F < todayF){

        //write to Log
        var sendToLog = [];
        var logSheet = ss.getSheetByName("Log");
        var logDate = sheets[i].getRange("A3").getValue();
        var sheetLastColumn = sheets[i].getLastColumn();

        sendToLog.push(logDate);
        sendToLog.push(sheetName);
        for (var j=2; j<sheetLastColumn+1; j++){
          var colHeading = sheets[i].getRange(2, j).getValue();
          var colName = sheets[i].getRange(3, j).getValue();
          sendToLog.push(colHeading+":"+colName);
        }

//        ["12/16/14","Lab1","Per1:bj","Per2:Sara"];
        logSheet.appendRow(sendToLog);

        //add new day
        var lastDay =  new Date(sheets[i].getRange(sheets[i].getLastRow(), 1).getValue());
        var dayOfWeek = Utilities.formatDate(lastDay, "EST", "EEE");
        if (dayOfWeek == 'Fri'){
          var nextMon = new Date(lastDay);// This needs to be two lines for some reason.
          nextMon.setDate(lastDay.getDate()+3);
          sheets[i].appendRow(["-"]);
          sheets[i].appendRow([nextMon]);
        } else{
          var nextDay = new Date(lastDay);// This needs to be two lines for some reason.
          nextDay.setDate(lastDay.getDate()+1);
          sheets[i].appendRow([nextDay]);
        }
        sheets[i].getRange("a:a").setNumberFormat('DDD, MM/dd');

        //remove tody
        var dayOfWeek2 = Utilities.formatDate(cellA3, "EST", "EEE");
        if (dayOfWeek2 == 'Fri'){
          sheets[i].deleteRow(4);
        }
        sheets[i].deleteRow(3); 
      }
    }
  }
  // for testing
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Log").getRange(1,4,1,2).setValues([["Last Update", new Date()]]);
}

这是我用来创建触发器的代码。

  //  Configure trigger
  var projectTriggers = ScriptApp.getProjectTriggers();
  if (projectTriggers.length == 0){
    ScriptApp.newTrigger('updateDay').timeBased().everyHours(1).create();
  }

对于附加组件,您需要以编程方式创建触发器,您可以在此处找到相关文档和示例:https://developers.google.com/apps-script/guides/triggers/installable#managing_triggers_programmatically

您不想将项目触发器(这些在项目范围内设置)与插件一起使用...您需要使用用户触发器,每个文档实例每个插件设置为 1 个。附加组件用户触发器仅限于时钟和表单类型,并遵循一组不同的规则,包括降低时间触发器的频率(每小时最多 1 次),并且每个文档每个用户每种类型仅限一个触发器。