确认电子邮件Google表单在填写所有问题时效果很好。但是,如果未填写不需要的问题,确认邮件将返回下一个问题的第一个答案。 在下面的代码中,不需要var achternaam。我已尝试使用if语句返回值“n.v.t.” (if(achternaam ==“”); {achternaam ==“n.v.t。”})。不幸的是,这也不起作用。
如何解决这个问题?
function Initialize() {
var triggers = ScriptApp.getScriptTriggers();
for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("onFormSubmit")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
function onFormSubmit(e) {
var tijdstip = e.values[0];
var voornaam = e.values[1];
var achternaam = e.values[2];
var email = e.values[3];
var wn = e.values[4];
if (achternaam ==""); {achternaam == "n.v.t."}
var emailTo = email;
var subject = "Bevestiging";
var emailBody =
"Beste " + voornaam + ",\n\n" +
"Je hebt onderstaande gegevens naar ons verzonden \n" +
"Met vriendelijke groet,\n\n" +
"Technische Commissie\n\n" +
"AchternaamTijdtip afmelding: " + tijdstip + "\n" +
"Voornaam; " + voornaam + "\n" +
"Achternaam; " + achternaam + "\n" +
"e-mailadres; " + email + "\n" +
"Wel of niet? " + wn + "\n" +
"--------------";
/**
* Un-comment this to use it for debugging
*/
// for (var i in e.values) {
// Logger.log("" + i + ":" + e.values[i]);
// }
MailApp.sendEmail(emailTo,subject,emailBody);
}
答案 0 :(得分:0)
使用数组可以完全解决问题。参见下面Amit Agarwal制作的剧本,见http://www.labnol.org/internet/google-docs-email-form/20884/#premium。它很棒!在他的剧本下面:
/* Send Google Form by Email v2.0 */
/* For customization, contact the developer at amit@labnol.org */
/* Tutorial: http://www.labnol.org/?p=20884 */
function Initialize() {
var triggers = ScriptApp.getScriptTriggers();
for(var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("SendGoogleForm")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
function SendGoogleForm(e)
{
try
{
// You may replace this with another email address
var email = Session.getActiveUser().getEmail();
// Optional but change the following variable
// to have a custom subject for Google Form email notifications
var subject = "Google Docs Form Submitted";
var s = SpreadsheetApp.getActiveSheet();
var columns = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
// Only include form fields that are not blank
for ( var keys in columns ) {
var key = columns[keys];
if ( e.namedValues[key] && (e.namedValues[key] != "") ) {
message += key + ' :: '+ e.namedValues[key] + "\n\n";
}
}
// This is the MailApp service of Google Apps Script
// that sends the email. You can also use GmailApp for HTML Mail.
MailApp.sendEmail(email, subject, message);
} catch (e) {
Logger.log(e.toString());
}
}