Home > Mobile >  Trying to run more than one function onEdit - Google Sheets
Trying to run more than one function onEdit - Google Sheets

Time:02-11

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"

CodePudding user response:

Try

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

CodePudding user response:

Thank you, Mike!

That worked alright. :)

Cheers, mate.

  • Related