Google-sheets – Email notification if cell value goes below set amount

google sheetsgoogle-apps-script

I'm having trouble finding a Google sheet script that does what I need so I figured I would ask if someone could help me. Basically I have a simple sheet setup to track inventory of one item. There is a formula in "G1" on sheet "QAI Stickers" that calculates the remaining inventory and I would like to add a script that emails specific people when the value drops below 11. I also just want it to email when just that value changes and not just when any value in the sheet changes.

Here is what I've been trying to use. I have a trigger setup to run on edit, but it seems to only run if I push play on the script. The program is also telling me that lines 5 & 8 are deprecated.

 function myNotification() {  
  var ss = SpreadsheetApp.getActiveSpreadsheet();  
  var value = ss.getSheetByName("QAI Stickers").getRange("G1").getValue();  
  if( value < 11 ) {  
    var last = ScriptProperties.getProperty("last");  
    value = value.toString();  
    if( value != last ) {  
     var email = Session.getUser().getEmail();  
     MailApp.sendEmail(email, 'My Notification',  
                    'new value: '+value+'\n\n'+ss.getUrl());  
     ScriptProperties.setProperty("last", value);  
    }  
  }  
}  

Best Answer

Make use of triggers to run your script automatically. See Triggers and events Guide

Regarding the deprecrated lines, instead of ScriptProperties we should use the Properties Service.