let expDate = null;
if (expirationCell instanceof Date) {
expDate = expirationCell;
} else if (expirationCell && typeof expirationCell === "string") {
// prova a parsare stringa ISO o formati comuni
const parsed = new Date(expirationCell);
if (!isNaN(parsed)) expDate = parsed;
}
if (!expDate) continue;
const expKey = Utilities.formatDate(expDate, tz, "yyyy-MM-dd");
if (expKey === todayKey) {
const subject = `${studentName} has reached the end of the behavior suspension period.`;
const formattedDate = Utilities.formatDate(expDate, tz, "EEE, MMM dd, yyyy");
const body = `Hi Robert,\n\nThis is an automated notification. The behavior suspension period for student ${studentName} ends today (${formattedDate}).\n\nRegards,\nAutomated Script`;
MailApp.sendEmail(emailRecipient, subject, body);
Logger.log(`Email sent for ${studentName} (${formattedDate})`);
}--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/CACrgDdoS-gDne5DHsGgGgrtYY1ctytVYRgBmyMp78MnnVU5kfQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
row) instead of the specific columns (row[0] and row[4]). In addition, the email address contained invalid characters.Here is your code rewritten using Object-Oriented Programming and modern JavaScript (V8) methods. It fixes the indexing issues and formats the date exactly as requested.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
That is correct. All simple triggers like onEdit, onOpen, onChange.. can not call any facility outside of the document container itself.
You can change the name of the function and then define it as a manual trigger and authorize it and it will then run and perform those actions.
you should be able to define the manual trigger from the Apps-Script editor window. On left hand side, choose triggers, then from that window, click on bottom right the add trigger button to create the trigger as you see in attached screenshot.

Thanks George — clear and helpful. I’ll rename the function, create an installed trigger, authorize it, and run the tests you suggested. I’ll report back with results or any errors. If you have a recommended guide or exact steps for creating the installed trigger, please share.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
You are welcome!
Please note that I haven't tested this directly in your spreadsheet. I built and refined this solution entirely based on the details and the original code you shared in your message.
To make this completely foolproof, you don't need to edit the code at all anymore.
I created a custom menu that handles everything. When you click Suspension System > Initialize System, a prompt will ask you for the name of the sheet tab. The script will find it and save its underlying Sheet ID. This is a great safeguard because if anyone renames the sheet later, the code won't break!
To keep it secure, this menu only appears for the Owner. Because it uses an "Installable Trigger," it runs under your permissions. If another authorized teacher updates a date to today, the system will seamlessly detect their edit and send the notification email directly to your inbox.
How to use it:
Delete all previous scripts and paste the code below.
Save and refresh your Google Sheets page.
Click the new Suspension System > Initialize System menu.
Type the name of your sheet when prompted and click OK. The script will automatically create the daily and edit triggers for you.


To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/3032740d-f2d3-4fd5-a498-ca3d5bd1659f%40gmail.com.