I am limited in my abilities so please be patient with me. I have the following task. My first tab has a log of student names, time stamps, and locations. I have written a script that triggers an onEdit email when the last column has “Guidance Counselor” typed in. I am trying to alter the script so that the following task can occur. I want an onEdit email to be triggered when a specific student’s name is entered into column 1. However, I do not want to enter the script each time and type the list of student names that I want/need an email to be triggered for. My thought process is that I want to be able to have a separate tab with a list of names that I can update on a regular basis and when a cell value in column 1 matches a name that is in the other tab it triggers an email on that edit.
Here is the url for my sheet
https://docs.google.com/spreadsheets/d/1JiZXEtB3-B0C10TEy2CIFjdckhH3THNZaVo7lVsIg9k/edit?usp=sharing
Here is the code for my script so far that triggers an email on “Guidance Counselor” I know its not that clean.
function emailonEdit(e) {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// EVENT VARIABLES
let range = e.range;
let row = e.range.getRow();
let col = e.range.getColumn();
let cellValue = sheet.getActiveCell().getValue();
let studentName = sheet.getRange(row,1).getValue();
let user = Session.getActiveUser().getEmail();
let cellLocation = sheet.getActiveCell().getA1Notation();
let url = "https://docs.google.com/spreadsheets/d/1z7j1qB6JJ3q6IzGn8eL1R4-hJs8-GqMXlu9NpiakUts/edit#gid=0"
if ( col == 6 && cellValue == "Guidance Counselor") {
// Browser.msgBox('It works');
MailApp.sendEmail(
'fayj@bathwildcats.org',
studentName + ' enroute to GUIDANCE!',
url + '&range=' + cellLocation
);
}
if ( col == 6 && cellValue == "Guidance Counselor") {
// Browser.msgBox('It works');
MailApp.sendEmail(
'jimfay55@icloud.com',
studentName + ' enroute to GUIDANCE!',
url + '&range=' + cellLocation
);
};
if ( col == 6 && cellValue == "Guidance Counselor") {
// Browser.msgBox('It works');
MailApp.sendEmail(
'NavianceStudent2022@gmail.com',
studentName + ' enroute to GUIDANCE!',
url + '&range=' + cellLocation
);
};
}