【发布时间】:2016-03-03 02:57:45
【问题描述】:
我正在修改 Amit 的代码(在此处找到:http://labnol.org/?p=20884) 尝试使用 Google 表单中的数据发送电子邮件。 但我要抓住的是他的钥匙和专栏。 我想专门从有问题的行中获取前 1 和 2 列的数据,并将其用作主题字段中的 var。 但是输出(在电子邮件中和发送到体式时)被列为未定义。我哪里做错了?
/*
Send Google Form Data by Email v4.2
Written by Amit Agarwal amit@labnol.org
Source: http://labnol.org/?p=20884
*/
/**
* @OnlyCurrentDoc
*/
function Initialize() {
try {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers)
ScriptApp.deleteTrigger(triggers[i]);
ScriptApp.newTrigger("EmailGoogleFormData")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit().create();
} catch (error) {
throw new Error("Please add this code in the Google Spreadsheet");
}
}
function EmailGoogleFormData(e) {
if (!e) {
throw new Error("Please go the Run menu and choose Initialize");
}
try {
if (MailApp.getRemainingDailyQuota() > 0) {
// You may replace this with another email address
var email = "x+00000000@mail.asana.com";
// Enter your subject for Google Form email notifications
var key, entry,
message = "",
ss = SpreadsheetApp.getActiveSheet(),
cols = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0];
// Iterate through the Form Fields
for (var keys in cols) {
key = cols[keys];
entry = e.namedValues[key] ? e.namedValues[key].toString() : "";
// Only include form fields that are not blank
if ((entry !== "") && (entry.replace(/,/g, "") !== ""))
message += key + ' :: ' + entry + "\n\n";
var first = entry[1];
var last = entry[2];
var subject = first+" "+last+": Interested Candidate";
}
MailApp.sendEmail(email, subject, message);
}
} catch (error) {
Logger.log(error.toString());
}
}
/* For support, contact developer at www.ctrlq.org */
【问题讨论】:
-
对于每一行数据,您要发送一封电子邮件吗?
-
嗨@SandyGood!你是我的英雄。是的。工作表的每个新行都会发送一封新电子邮件。
-
找到这个话题。也许我可以使用它,但我又迷路了:stackoverflow.com/questions/20037987/…
标签: google-apps-script google-sheets google-apps google-forms asana