0

I have a simple GoogleSheet which is meant to send an email if one edits 4th column on a "TESTING" tab.

I wrote a basic script, with static recipient, body and subject.

I authorized the function upon authorization request.

The recipient is one of my hotmail accounts (which has no linkage to this Google sheet, so should not have an issue raised by MailApp.sendEmail Not Working?.

I have tried both "GmailApp.sendEmail" and "MailApp.sendEmail", but the behavior is the same:

When I run my onEdit() function inside the editor, everything works exactly as expected, and the email function works if the cursor is in the appropriate 4th column on the appropriate sheet.

But after I save the code, and try to evince the same behavior by editing a cell in column 4 on that sheet, I get as far as the step1 break but the email does not get sent (I did check the spam folder, after reading the discussion on StackOverflow on the subject)

function onEdit() { 
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "TESTING" ) 
  {
 var r = s.getActiveCell();
 var col = r.getColumn(); 
 var row = r.getRow();
 if( col == 4)
 {
    s.getRange(row, 5).setValue("step1");          // did we get this far?
    MailApp.sendEmail("me@hotmail.com", "step1", "step1");
    s.getRange(row, 6).setValue("step2");          // do we get this far?
    }
  } 
 }

The active sheet is pretty simple:

enter image description here

Any idea what would be causing such behavior?

Community
  • 1
  • 1
user1766394
  • 303
  • 1
  • 2
  • 9

1 Answers1

0

And the answer was apparently in one of the previous threads, courtesy of Serge. I had to go into Resources and edit Current Project Triggers to allow for onEdit triggers.

user1766394
  • 303
  • 1
  • 2
  • 9