I'm create Google form and google app script with sendFormByEmail function, also I set on form submit trigger for this function, my issue is this script run two time on form submit and I'm getting two email, I want only single email on form submit. my script code is below.
var no_repeat=0;
function sendFormByEmail(e){
var email = "[email protected]";
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
var subject = "Success Assessment";
var total=0;
var roll_on=0;
message+="test massage";
message+="<table cellpadding='3' style='color: #0F1F4C;'>";
for(var i in headers) {
if(headers[i]=='Please enter your email address to receive your results'){
email=e.namedValues[headers[i]].toString();
}
if(headers[i]!='Please enter your email address to receive your results'){
if(headers[i]!='Timestamp'){
if(e.namedValues[headers[i]]!=''){
total = parseInt(e.namedValues[headers[i]])+parseInt(total);
}
message +="<tr >";
message += '<td >'+headers[i]+'</td><td >'+e.namedValues[headers[i]].toString()+ "</td>";
message +="</tr>";
roll_on++;
}
}
}
message +="<tr >";
message += "<td ><b> YOUR SCORE </b></td><td ><b>"+total+"</b></td>";
message+="</tr></table>";
// Send the email
if(email!='' && email!=null){
if(no_repeat==0){
MailApp.sendEmail(email, subject,"",{htmlBody: message});
}
no_repeat++;
}
}
Go to script.google.com . At the left, click My Triggers. To delete a trigger, at the right of the trigger, click More more_vert > Delete trigger. Note: Simple triggers like onOpen() can't be deactivated from this page; instead, you must edit the appropriate script and remove or rename the onOpen() function.
There are a few possible causes for these errors: A Google server or system is temporarily unavailable. Wait for a few moments and try running the script again. There is an error in your script that doesn't have a corresponding error message.
Triggers let Apps Script run a function automatically when a certain event, like opening a document, occurs. Simple triggers are a set of reserved functions built into Apps Script, like the function onOpen(e) , which executes when a user opens a Google Docs, Sheets, Slides, or Forms file.
This is a known issue at Google's end and they are working on a fix:
Our engineering team is working on the issue, but we don't have any estimates as to when it will be fixed. I advise applying the LockService logic as shown in update #22, which should work around the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With