I have an appscript that triggers an email to certain users on form submission. The trigger works fine, except, it is sending out duplicate emails to the users.
I have tried adding a column to my underlying google sheet to mark if an email was sent and if it was sent, do not send another email. It did not work. There is a lot more code, but, I have included the relevant piece.
var _sheet = sheet;
var _data = getRowsData(_sheet);
var _markPending = function(d) {
d.state = PENDING_STATE;
d.identifier = Utils.generateUUID();
d.budgeted = FIN_BUDGET;
d.DepartmentName = FIN_SUB;
d.financeDirectorApproval = FIN_APPROVE;
d.finalFinanceApproval = CFO_STATE;
Logger.log(_markPending);
manager_email = d[SETTINGS.MANAGERS_EMAIL_COLUMN_NAME].match(EMAIL_REGEX);
d.manager_email = manager_email
if (d.mailSent != 'Sent')
{
MailApp.sendEmail(SETTINGS.HR_MANAGER_EMAIL_ADDRESS, subject2, "",{ htmlBody: message});
d.mailSent = MAIL_SENT;
};
Head onFormSubmit Trigger May 21, 2019, 9:57:39 AM 3.141 s
Completed
Head onFormSubmit Trigger May 21, 2019, 9:57:39 AM 3.298 s
Completed
Logger.log("Good afternoon, Good Evening and Good night");
var sheet = getSpreadsheet().getSheetByName(RESPONSES_SHEET);
handler = SheetHandler(sheet);
handler.processSheet();
writeToLog();
var lastRowValues = sheet.getRange(sheet.getLastRow(),1,1,sheet.getLastColumn()).getValues();
var Var1 = lastRowValues[0][1];
var Var2 = lastRowValues[0][13];
var Var3 = lastRowValues[0][17];
var Var4 = lastRowValues[0][16];
var Var5 = lastRowValues[0][2];
var Var6 = lastRowValues[0][7];
var Var7 = lastRowValues[0][8];
var Var8 = lastRowValues[0][3];
var Var9 = lastRowValues[0][5];
var Var10 = lastRowValues[0][27];
var subject2 = "Form Input - " + Var1 + " - " + Var2
var manager_email = "[email protected]";
var emailBody = "Labe1: " + Var1
+ "<br /> \ Label2: " + Var2
+ "<br /> \ Label3: " + Var3
+ "<br /> \ Label4: " + Var4
+ "<br /> \ Label5: " + Var5
+ "<br /> \ Label6: " + Var6
+ "<br /> \ Label7: " + Var7
+ "<br /> \ Label8: " + Var8
+ "<br /> \ Label9: " + Var9;
MailApp.sendEmail(manager_email, subject2, "",{ htmlBody: emailBody });
// } ;
//
}; ```