我添加了一些菜单并在 onOpen() 中启用了自定义可安装的 onEdit 触发器,如下所示。所有菜单均按预期设置,但未设置可自定义安装的 onEdit 触发器。似乎它没有执行那些删除和创建触发器的行。这里发生了什么?解决方案?
function onOpen() {
var ass = SpreadsheetApp.getActiveSpreadsheet();
ass.addMenu("TriggerOn", [null, {name: "Disable OnEditTrigger", functionName: "disableOnEditTrigger"}]);
ass.addMenu("AlertOn", [null, {name: "Alert Off", functionName: "alertOff"}]);
ass.addMenu("EmailBodyHtml", [null, {name: "TextBody", functionName: "textbody"}]);
ass.addMenu("Setup", [null, {name: "MasterTemplate", functionName: "setMasterTemplate"}]);
//delete all previous triggers
var allTriggers = ScriptApp.getScriptTriggers();
// Loop over all triggers
for(var i=0; i < allTriggers.length; i++)
ScriptApp.deleteTrigger(allTriggers[i]);
// Create onEdit trigger using the Spreadsheet
var onEditTrigger = ScriptApp.newTrigger("myOnEdit")
.forSpreadsheet(ass)
.onEdit()
.create();
ScriptProperties.setProperty("alert", "1");
ScriptProperties.setProperty("emailbody", "htmlbody");
}