【发布时间】:2015-03-20 19:53:49
【问题描述】:
我在 Google 表单中使用表单通知插件。我已经编辑了 Code.gs 和 CreatorNotification.html 文件,一切正常 - 提交 Google 表单后,我会收到一封电子邮件。现在我正在尝试将该表单提交中的一些字段放入电子邮件中。但是随着我在下面添加的编辑,电子邮件通知停止工作。
在我的 Code.gs 脚本中:
function sendCreatorNotification() {
var form = FormApp.getActiveForm();
var settings = PropertiesService.getDocumentProperties();
var responseStep = settings.getProperty('responseStep');
responseStep = responseStep ? parseInt(responseStep) : 10;
function onFormSubmit(e) {
//Get information from form and set as variables
var First_Name = e.value[2];
// If the total number of form responses is an even multiple of the
// response step setting, send a notification email(s) to the form
// creator(s). For example, if the response step is 10, notifications
// will be sent when there are 10, 20, 30, etc. total form responses
// received.
if (form.getResponses().length % responseStep == 0) {
var addresses = settings.getProperty('creatorEmail').split(',');
if (MailApp.getRemainingDailyQuota() > addresses.length) {
var template = HtmlService.createTemplateFromFile('CreatorNotification');
template.summary = form.getSummaryUrl();
template.responses = form.getResponses().length;
template.title = form.getTitle();
template.responseStep = responseStep;
template.formUrl = form.getEditUrl();
template.notice = NOTICE;
template.firstname = First_Name;
var message = template.evaluate();
MailApp.sendEmail(settings.getProperty('creatorEmail'),
form.getTitle() + ': Case submission',
message.getContent(), {
name: ADDON_TITLE,
htmlBody: message.getContent()
});
}
}
}
}
在 CreatorNotification.html 我有:
<p><i>Form Notifications</i> (a Google Forms add-on) has detected that the form
titled <a href="<?= formUrl?>"><b><?= title ?></b></a> has received
<?= responses ?> responses so far.</p>
<p><a href="<?= summary ?>">Summary of form responses</a></p>
<p>First Name:</p> <?= firstname ?>
任何方向都将不胜感激。
【问题讨论】:
-
如果您现在不知道,您需要调试代码并找出失败的行。在要检查变量值的地方添加
Logger.log('this value: ' + variableName);语句,然后查看日志,或使用调试器逐步执行代码。 Debugger and breakpoints -
您现在在
sendCreatorNotification()函数中拥有了onFormSubmit函数。原来是这样的吗? -
我已经添加了 onFormSubmit 函数,希望它能够工作。它原本不在那里。如果我删除它,电子邮件通知将再次起作用。所以,我想问题是,如何将变量(表单中的一个或多个响应)填充到模板中?
标签: forms email google-sheets