Google Sheets – Receive Notification When Specific Tab Changes

google sheetsgoogle-apps-script

If would like to receive an email notification if a new row is added to a specific tab in a Google Sheets.

The default notification rule settings are too limited and the Google Sheets Add-on Store does not provide any suitable add-on script:

enter image description here

How to send such notifications with a Google Apps script?

Best Answer

The event object helps here, specifically its changeType property, which tells the script what kind of change happened. If this change is INSERT_ROW, and the name of sheet matches the one you want, then an email is sent using MailApp.

function notify(e) {
  var sheet = SpreadsheetApp.getActiveSheet();
  if (sheet.getName() == 'Tracked Sheet' && e.changeType == 'INSERT_ROW') {
    MailApp.sendEmail('myemail@gmail.com', 'Row Added', 'A row was added to your sheet.');
  }
}

To use this, add a trigger (Resources > Current project's triggers) with the properties "From spreadsheet | On Change".