0
votes

I'm trying to make it so that when a dropdown cell reads "Send" an email is sent. The email address and message need to be dynamic. The onEdit event is firing but it stops when declaring emailAddress. Why is this happening? I have a lot of VBA experience but much less GAS experience.

/*
 * on sheet change, if correct cell
 */
function onEdit(e) {      
  if (e.range.getSheet().getName() === 'Sheet1') {
    var sheet = SpreadsheetApp.getActiveSheet();
    if (e.range.getA1Notation() === 'D2' && e.value === 'Send') {
        sheet
          .getRange('D2')
            .clearContent(); 
      logIt('good through here');
    var emailAddress = sheet.getRange(2, 1).getValue;
      logit('will not show');
    var message = sheet.getRange(2, 2).getValue;
    var subject = "GAS -- Automated Email";
    MailApp.sendEmail(emailAddress, subject, message);
      logIt('testEnd');
    }
  }    
}

function logIt(message) {
  SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().appendRow([new Date(),message]);
}
1

1 Answers

1
votes

On Edit cannot send emails:

Look at "Restrictions" on this apps script simple triggers explanation.

https://developers.google.com/apps-script/guides/triggers

Also, your "will not show" message is not displaying because you have a typo: logit rather than logIt.