Apps script installable trigger isn’t called.

huangapple go评论54阅读模式
英文:

Apps script installable trigger isn't called

问题

我试图安装和触发一个简单的onEdit触发器,但它似乎没有生效。

然后我尝试安装一个可安装的onEdit2触发器 - 但当我调试调用“foo”时,它似乎不会触发。

是否有注意事项?

function foo() {
  let trigger = createInstallableTrigger("myTrigger", "onEdit2", "每次编辑单元格时", onEdit);
  trigger.create();
  
  trigger = ScriptApp.getTrigger("myTrigger");
  trigger.install();
}

/**
 * 编辑电子表格时触发的事件处理程序。
 * @param {Event} e onEdit事件。
 * @see https://developers.google.com/apps-script/guides/triggers#onedite
 */
function onEdit2(e) {
  // 在编辑的单元格上设置注释,以指示最后修改的时间。
  const range = e.range;
  range.setNote('上次修改时间:' + new Date());
}
英文:

Iwas trying to install and trigger a simple onEdit trigger, but it didn't show can effect.

Than I've tried to install an installable onEdit2 trigger - but it won't seem to fire when I debug calling "foo"/

Is there a caveat?

function foo() {
let trigger = createInstallableTrigger("myTrigger", "onEdit2", "every time a cell is edited", onEdit);
trigger.create();

trigger = ScriptApp.getTrigger("myTrigger");
trigger.install();
}



/**
 * The event handler triggered when editing the spreadsheet.
 * @param {Event} e The onEdit event.
 * @see https://developers.google.com/apps-script/guides/triggers#onedite
 */
function onEdit2(e) {
  // Set a comment on the edited cell to indicate when it was changed.
  const range = e.range;
  range.setNote('Last modified: ' + new Date());
}

答案1

得分: 1

Function foo似乎是尝试以编程方式创建一个可安装的 onEdit 触发器的尝试。我怀疑它来自ChatGPT,因为它包含了无关的 (createInstallableTrigger) 和非法的 (trigger.install()) 函数调用。

另一方面,文档 包括一个用于可安装的 onEdit 触发器的脚本的简单示例。

/**
 * 创建当电子表格被编辑时的触发器
 */
function createSpreadsheetOnEditTrigger() {
  var sheet = SpreadsheetApp.getActive();
  ScriptApp.newTrigger("onEdit2")
    .forSpreadsheet(sheet)
    .onEdit()
    .create();
}
英文:

Function foo appears to be an attempt to programmatically create a installable onEdit trigger. I suspect that it is sourced from ChatGPT because it contains both irrelevant (createInstallableTrigger) and illegal (trigger.install()) function calls.

OTOH, the documentation includes a simple example of the script for an installable onEdit trigger.


/**
 * Creates a trigger for when a spreadsheet is edited
 */
function createSpreadsheetOnEditTrigger() {
var sheet = SpreadsheetApp.getActive();
ScriptApp.newTrigger("onEdit2")
  .forSpreadsheet(sheet)
  .onEdit()
  .create();
}

huangapple
  • 本文由 发表于 2023年5月7日 23:20:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76194762.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定