Forms 谷歌在通知电子邮件中的表单响应

Forms 谷歌在通知电子邮件中的表单响应,forms,email,google-sheets,Forms,Email,Google Sheets,我正在谷歌表单中使用表单通知插件。我已经编辑了Code.gs和CreatorNotification.html文件,一切都很好——当提交谷歌表单时,我会收到一封电子邮件。现在我正在尝试将表单提交中的一些字段输入到电子邮件中。但随着我在下面添加的编辑,电子邮件通知停止工作 在Code.gs脚本中,我有: function sendCreatorNotification() { var form = FormApp.getActiveForm(); var settings = Pr

我正在谷歌表单中使用表单通知插件。我已经编辑了Code.gs和CreatorNotification.html文件,一切都很好——当提交谷歌表单时,我会收到一封电子邮件。现在我正在尝试将表单提交中的一些字段输入到电子邮件中。但随着我在下面添加的编辑,电子邮件通知停止工作

在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 ?>
表单通知(谷歌表单附加组件)检测到该表单
我收到了
迄今为止的答复

名字:

任何方向都将不胜感激。

您正在尝试运行两个触发器。“附加”代码创建了一个触发器。该加载项创建一个“可安装”触发器。您已经为正在提交的表单设置了一个触发器。
onFormSubmit(e)
功能是一个“简单”触发器。因此,有两个触发器设置为在提交表单时运行。所以,你制造了一场冲突。如果在参考资料菜单中,在当前项目的触发器下,您应该会看到为
sendCreatorNotification()
函数定义的触发器

这是你可以尝试的。您不需要单独的
onFormSubmit(e)
简单触发器。
sendCreatorNotification()
函数具有可用的事件对象。只需将
e
添加到
sendCreatorNotification()
函数:

sendCreatorNotification(e)

编写代码以从
e

中获取值。如果您现在不知道,则需要调试代码并找出哪一行失败。添加
Logger.log('此值:'+variableName)语句,您可以在其中检查变量的值,然后查看日志,或者使用调试器逐步完成代码。现在,在
sendCreatorNotification()
函数中有了
onFormSubmit
函数。原来是这样吗?我添加了onFormSubmit函数,希望它能正常工作。它本来就不在那里。如果我删除它,电子邮件通知将再次工作。所以,我想问题是,我如何将变量(表单中的一个或多个响应)填充到模板中?不,我只添加了以下行:function onFormSubmit(e){//Get information from form and set as variables var First_Name=e.value[2];template.firstname=First_Name;}原始代码可以在这里找到:好的,我现在使用sendCreatorNotification(e)并删除了多余的触发器。然而,它似乎不喜欢从Google表单中获取值的代码。调试模式显示此错误:无法从以下行的未定义中读取属性“值”:var First_Name=e.values[1];