1
votes

I'm looking for a way to trigger an automatic email notification to myself when any value within a column of data ("Column H") drops below a certain threshold. Ideally, the notification would include the name associated with the value, which is stored in a separate column of the spreadsheet ("Column A").

My best guess so far is that I need to use an onEdit function, which has a condition that checks the values within the specific column and then sends a email when a value meets that condition.

Here's what I have so far, but I'm having issues with completing this.

function onEdit(e){
   var sheet = SpreadsheetApp.getActiveSheet();
   var data = sheet.getDataRange("H1:H200").getValues();
   var newValue = e.value;
}
if (newValue < "10"){
   MailApp.sendEmail("[email protected]","TEST", "TEST");
}

Any help would be appreciated. Thanks!

Update: Here's what I currently have, following the creation of an installable trigger. I'm getting a 'value' undefined error at the moment and think that possibly syntax/formatting are to blame.

function createSpreadsheetEditTrigger(){
    var ss = SpreadsheetApp.getActive();
    ScriptApp.newTrigger(StationeryEdited)
        .forSpreadsheet(ss)
        .onEdit()
        .create();
    }

function StationeryEdited(e){
    var sheet = SpreadsheetApp.getActiveSheet();
    var data = sheet.getRange(2, 8, 200, 1).getValues();
    var newValue = e.value;
    if (newValue < "10"){
        MailApp.sendEmail("[email protected]", "TEST", "TEST");
    }
}
1
What about it doesn't work? Mind you that you need to use an installable onedit trigger see hereRobin Gertenbach
Hi Robin, Thanks for the heads up about the installable trigger. I've added to my code in order to account for that. At the moment, I'm getting a new error: "Cannot read property "value" from undefined. (line 4, file "Code")."jbarry1
Are you trying to run the onEdit in the script editor? That won't work as it runs without any parameters passed to itRobin Gertenbach
Thanks, Robin. That's really helpful! I've got the script running, but I'm still having authorization issues, despite switching to an installable onedit trigger. When I look at the execution log, everything seems to execute, but I receive an error saying that I'm not authorized to send the email.jbarry1
Did you rename your function when adding the installable trigger ?Serge insas

1 Answers

0
votes

enter image description here

Does this feature doesnt help you?

Tools >> Notification Rules