function myAlerts() {
// this runs based on daily trigger
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Reminders");
var range = sheet.getDataRange();
var values = range.getDisplayValues();
var lastRow = range.getLastRow();
var curDate = values[1][5]
var anyMatches = false;
var message = "";
var sheetUrl = ss.getUrl();
var email = Session.getActiveUser().getEmail();
var optionalEmail = values[2][1];
if (optionalEmail != "")
{ email = email + "," + optionalEmail;}
for (var i = 5; i < lastRow; i++)
{
// if today matches the alert date, send an alert
if (values[i][3].toString() == curDate.toString())
{
// add a message for this row if date matches
message = message + values[i][0] + " is due on the " + values[i][1] + "
\n";
// if there is a match, set anyMatches to true so and email gets sent
anyMatches = true;
}
} // ends for loop
// footer for message
message = message + "
\nThis reminder was generated by this spreadsheet:
\n" + sheetUrl;
if (anyMatches)
{ // send an email
MailApp.sendEmail({
to: email,
subject: 'Tiller Bill Pay Reminder',
htmlBody: message});
}
}