So, I'm trying to write a code that will send an email when a particular value appears in a cell. For this I'm using an installable OnEdit trigger as simple ones can't access mailApp.sendEmail. The installable trigger is for the following function:
function myOnEdit(e){
var ss = SpreadsheetApp.getActiveSheet();
var email_finished = "abc@email.com"
var r = e.range;
var heading = ss.getrange(1,range.getcolumn()).value
if (heading == "FINISHED" && r.getvlaues() == "√") {
MailApp.sendEmail(email_finished, "SOP Review", "SOP has been finished");
}
}
I'm getting an error that "e" is undefined. I'm wondering how I can reference the event object for the installable onEdit() trigger.
I'm an absolute Javascript noob, so please do enlighten me as much as you can my coding gurus!! Thanks in advance.
EDIT: As Serge said there were a bunch of typos. A side-effect of VBA coding! But I corrected the typos and changed how I was doing it:
function myonEdit(){
var ss = SpreadsheetApp.getActiveSheet();
var e = ss.getActiveCell();
var heading = ss.getRange(1, e.getColumn()).getValues();
var rvalue = e.getValue();
var email_finished = "abc@xyz.com";
var ui = SpreadsheetApp.getUi()
ui.alert("Are you sure?", ui.ButtonSet.OK)
if (heading == "FINISHED" && rvalue == "√") {
MailApp.sendEmail(email_finished, "SOP Review", "SOP has been finished");
}
}
The I added this on a manual trigger from Edit>>Current project's triggers. It works fine when debugging, sends email and all. However, when I edit the sheet, the code isn't triggered! I'm not sure what I'm doing wrong this time.