-1

I'm want to use this script to send an email when a cell is changed from "No" to "Yes" in column C (3) from a particular sheet - sheet1.

Could this code be modified to do that.

function sendNotification(e){
if(e.range.getColumn()==3 && e.value=='YES'){
 var recipients = "***********@gmail.com";
 var subject = "Update"+e.range.getSheet().getName();
 var body = "This cell has changed";
 var valColB=e.range.getSheet().getRange(e.range.getRow(),2).getValue();
 MailApp.sendEmail(recipients, subject, body)
 }
} 
user2240778
  • 309
  • 5
  • 16
  • Well, how are you running those functions? Note that they both attempt to access the property `range` from the variable you reference as `e`. The error clearly states that `e` is `undefined` - aka it was never initialized with a value. – tehhowch Aug 24 '18 at 19:33
  • Possible duplicate of [How can I test a trigger function in GAS?](https://stackoverflow.com/questions/16089041/how-can-i-test-a-trigger-function-in-gas) – tehhowch Aug 24 '18 at 19:34
  • How do I get it to run on a particular sheet? – user2240778 Aug 24 '18 at 19:46
  • It looks like this question is about resolving an error, not making this script run on a sheet. Consider reviewing the place where you took this function (which should be easy - you cite code that you take from others, right?) and determine how they meant this function to be used. – tehhowch Aug 24 '18 at 19:48
  • Further, you haven't even said how you get it to run. Start there, by asking a [good question](https://stackoverflow.com/help/how-to-ask) – tehhowch Aug 24 '18 at 19:50

1 Answers1

0

You need to set a trigger via the UI to run a sheet whenever it's edited. Conversely, you can rename your function to onEdit(e) and it will run whenever the sheet is edited.

Brian
  • 4,274
  • 2
  • 27
  • 55