Learn new Google Workspace Skills
In this project, client wanted to have a way to notify users that the data on a spreadsheet had changed. In this case it is an athletic event spreadsheet for a school. The client did not want to notify users of the sheet of any and all changes, rather just important changes that needed to be checked by parents, students, coaches that the should check the website for updated information.
Add Email Notification For A Sheet
In this tutorial see how to add an email notification system to a google sheet. In this use case a school wanted to be able to send push notification to a group of users if certain changes were made to an athletic calendar.
______________________________________________________________________________
// This creates the Menu and the Menu Items
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Send Emails')
.addItem('Email Coaches', 'sendEmails')
.addToUi();
}
function sendEmails() {
var sheet = SpreadsheetApp.getActive().getSheetByName('emaillist')
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 2)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var subject = "The Athletic calendar has been updated";
MailApp.sendEmail(emailAddress, subject, message);
}
}