简体   繁体   English

尝试运行多个 function onEdit - Google 表格

[英]Trying to run more than one function onEdit - Google Sheets

I wrote a script that displays a browser message box whenever the word "Lost" is input on a particular column (I:I) on the sheet, and I also wrote another that inputs the date and time on (A:A) when cell (B:B) is actualised.我编写了一个脚本,每当在工作表上的特定列 (I:I) 上输入“丢失”一词时,它就会显示一个浏览器消息框,我还编写了另一个脚本,在 (A:A) 单元格上输入日期和时间(B:B) 已实现。 But I'm struggling to merge them both since the onEdit function allows only a script.但我正在努力合并它们,因为 onEdit function 只允许一个脚本。

My script is as it follows:我的脚本如下:

 function onEdit(e) { myfunction1(); myfunction2(event); } function myfunction1() { var ActiveSheet= SpreadsheetApp.getActiveSheet(); var capture = ActiveSheet.getActiveCell(); if(ActiveSheet.getName() == 'Template' && (capture.getColumn() == 2)) { var add = capture.offset(0, -1); var data = new Date(); data = Utilities.formatDate(data, "GMT-03:00", "dd/MM/yyyy HH:mm:ss"); add.setValue(data); } } function myfunction2(event) { var sheet = event.source.getActiveSheet().getName() var editedCell = event.range.getSheet().getActiveCell(); if(sheet=="Template"){ if(editedCell.getColumn()==9 && event.value=="Lost"){ Browser.msgBox(' ⚠️ Make sure you enter the reason for loss.'); } } };

However, I keep getting error messages and can't find what I missed.但是,我不断收到错误消息并且无法找到我错过的内容。 I've also tried to separate all the variables above and open new functions, but no success.我也尝试过将上面的所有变量分开并打开新函数,但没有成功。

The last execution log error I got was: "9:22:57 AM Notice Execution started 9:22:57 AM Error我得到的最后一个执行日志错误是:“9:22:57 AM Notice Execution started 9:22:57 AM Error
ReferenceError: event is not defined onEdit @ Untitled.gs:3" ReferenceError:事件未定义 onEdit @ Untitled.gs:3”

Try尝试

function onEdit(event) {
  myfunction1();
  myfunction2(event);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM