简体   繁体   中英

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. But I'm struggling to merge them both since the onEdit function allows only a script.

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
ReferenceError: event is not defined onEdit @ Untitled.gs:3"

Try

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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