我在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 ?>
任何方向都会受到赞赏。
答案 0 :(得分:0)
您正在尝试运行两个触发器。 “附加”代码创建了一个触发器。加载项创建“可安装”触发器。您已为要提交的表单设置了一个触发器。 onFormSubmit(e)
函数是一个“简单”触发器。因此,您在设置表单时设置了两个触发器。所以,你创造了一个冲突。如果查看“资源”菜单,在“CURRENT PROJECT”的TRIGGERS下,您应该会看到为sendCreatorNotification()
函数定义的触发器。
这是你可以尝试的。您不需要单独的onFormSubmit(e)
简单触发器。 sendCreatorNotification()
函数具有可用的事件对象。只需将e
添加到sendCreatorNotification()
函数:
sendCreatorNotification(e)
编写代码以从e
中获取值。