Home > Mobile >  OnEdit only triggering when manually editing a cell
OnEdit only triggering when manually editing a cell

Time:05-27

I'm now able to only have an email sent when a cell in one sheet has something added to it and not when that thing is deleted. However, it only triggers an email when I manually add a value and not when a value is added via the appsheet it's linked to. I know it's possible because when I was playing around with it yesterday I could get emails to trigger from my phone via the appsheet, but now it only works if I type something random in a cell and press enter. I just can't see what might be wrong with this. Can anyone please help? Thank you!

function sendEmail() {
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sheet4=ss.getSheetByName('Copy');
  var emailAddress = sheet4.getRange(2,12).getValue();
  var subject = sheet4.getRange(2,13).getValue();
  var message = sheet4.getRangeList(['G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8'])
    .getRanges()
    .map(range => range.getDisplayValue())
    .join('\n');
MailApp.sendEmail(emailAddress, subject, message);
}

function onEdit(e) {

  if (e.source.getActiveSheet().getName() === `Trigger`) {
    if (e.range.rowStart >= 1 && e.range.columnStart >= 1) {
      if (`value` in e) sendEmail()
    }
  }
}

CodePudding user response:

With AppSheet 'edits' you will have to use onChange().

Try:

function onChange(e) {

  if (e.source.getActiveSheet().getName() === `Trigger`) {
    if (e.source.getActiveRange().getRow() >= 1 && e.source.getActiveRange().getColumn() >= 1) {

      if (e.source.getActiveRange().getValue() !== ``) sendEmail()

    }
  }

}

Note: This is specified to only work on an individual cell edit.

Let me know if this works for your AppSheet!

See:

  • Related