I've written the code below to send notification e-mails to specific individuals based on if a certain string is found in a cell. I want to know if I set the script to run on a "form submit" trigger if it will go through the full spreadsheet again (thus sending duplicate e-mails) or if it will just start with the new row that is added to the spreadsheet when a new Google form entry is submitted.
function notifySponsors() {
Logger.clear();
var s = SpreadsheetApp.getActiveSheet();
var data = s.getDataRange().getValues();
var data_len = data.length;
//define variables with each organization
var mustang = "Camp Mustang Counselor";
var chapel = "Chapel Tech Team";
var dgroup = "D-Group Leader";
var diversity = "Diversity Club";
var journalism = "Journalism";
var nhs = "National Honor Society Officer";
var robotics = "Robotics Club";
var stuco = "Student Council";
var ambassador = "Student Ambassador";
//Send e-mail to specific sponsors to notify that someone has submitted an application
for(var i=0; i<data_len; i++) {
var datastring = data[i][5].toString();
//E-mail Camp Mustang Sponsors
if(datastring.match(mustang)== mustang) {
var MustangString = data[i][1].toString()+" has submitted a Camp Mustang application";
MailApp.sendEmail("[email protected]", MustangString, MustangString);
MailApp.sendEmail("[email protected]", MustangString, MustangString);
Logger.log(MustangString);
}
//E-mail Chapel Sponsors
if(datastring.match(chapel)== chapel) {
var ChapelString = data[i][1].toString()+" has submitted a Chapel Team application";
MailApp.sendEmail("[email protected]", ChapelString, ChapelString);
Logger.log(ChapelString);
}
//E-mail D-Group Sponsors
if(datastring.match(dgroup)== dgroup) {
var DGroupString = data[i][1].toString()+" has submitted a D-Group Leader application";
MailApp.sendEmail("[email protected]", DGroupString, DGroupString);
MailApp.sendEmail("[email protected]", DGroupString, DGroupString);
Logger.log(DGroupString);
}
//E-mail Diversity Club Sponsors
if(datastring.match(diversity)== diversity) {
var DiversityString = data[i][1].toString()+" has submitted a Diversity application";
MailApp.sendEmail("[email protected]", "test 2", "New Application for D-Group");
Logger.log(DiversityString);
}
}
}