我有一个从SquareSpace运行的表单,它将客户数据输入到Google表格。我目前正在运行以下脚本,但触发器OnFormSubmit不起作用。我必须进入并手动运行脚本。
function FormConfirmationEmail() {
var sheetname = "Request Financial Assistance"
var columnnumber = 6
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheetname);
if (sheet.getRange(sheet.getMaxRows(),1).getValue() != "") {
var lastrow = sheet.getMaxRows()
} else {
var count = 0
for (var i = 0; i < sheet.getMaxRows(); i++) {
if (sheet.getRange(sheet.getMaxRows()-i,1).getValue() != "") {
var lastrow = sheet.getMaxRows()-i
break;
}
}
}
var email = sheet.getRange(lastrow,columnnumber).getValue();
var emailPattern = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|aero|asia|biz|com|coop|edu|gov|info|int|jobs|mil|mobi|name|museum|name|net|org|pro|tel|travel)\b/;
var validEmailAddress = emailPattern.test(email);
if (validEmailAddress == true) {
var message = "<HTML><BODY>"
+ "<P>This is an automated form completion email. Thanks for submitting!"
+ "</HTML></BODY>";
MailApp.sendEmail(email, "Form Completion Email", "", {htmlBody: message});
sheet.getRange(lastrow,13,1,1).setValue("Email Sent");
} else{
sheet.getRange(lastrow,13,1,1).setValue("Email not Sent - Invalid Email Address submitted");
}
}
谁能看到我做错了什么?
答案 0 :(得分:0)
您可以将触发器放在收集回复的Google表格中,并且表单提交触发器应该有效。
ScriptApp.newTrigger("FormConfirmationEmail")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
此外,您可以使用传递给FormSubmit函数的e参数来解析并通过电子邮件发送用户提交的数据,而不是使用getMaxRow()。