Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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"

I hope you can help me. 🙂

Cheers.

>Solution :

Try

function onEdit(event) {
  myfunction1();
  myfunction2(event);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading