我使用sendFormByEmail函數創建Google表單和Google應用腳本, 另外我在表單上爲此函數設置了提交觸發器, 我的問題是這個腳本在表單上運行兩次,我收到兩封電子郵件, 我只需要填寫一份表單提交的電子郵件。我的腳本代碼如下。腳本在Google表單提交觸發器上運行兩次
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++;
}
}
嗨,阿米特我已經gothrouth它befor張貼我的問題在這裏, 和「lock.waitLock」不爲我工作我試過了,根據 解決方案#22:https://code.google.com/p /谷歌 - 應用程序 - 腳本的問題/問題/細節?ID = 4752#C22 – 2015-02-11 13:16:18