发出来自Google表单的响应的问题,显示错误“" TypeError:无法读取属性“值"来自未定义. (第2行,文件“代码") [英] Issue making a response from a google form showing error ""TypeError: Cannot read property "values" from undefined. (line 2, file "Code")""

查看:166
本文介绍了发出来自Google表单的响应的问题,显示错误“" TypeError:无法读取属性“值"来自未定义. (第2行,文件“代码")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google表单中,我试图创建一个电子邮件响应,其中包含在表单响应中生成的案例编号(标题为列的代码),但不幸的是,我遇到了错误:

In Google Forms, I am attempting to create an email response that includes a case number that is generated in the form responses (column titled code) but unfortunately, I have come across the error:

typeError:无法从未定义中读取属性值". (第2行,文件代码")

typeError: Cannot read property "values" from undefined. (line 2, file "Code")

我是一个完全的新手,但是我已经设置了触发功能,并在回复中发送的电子邮件中收到此错误.

I am a complete novice regarding this but I have set the trigger function and am given this error in the email that is sent in a reply.

在下面找到回复文档的副本:

Find a copy of the responses docs below:

https://docs.google.com/spreadsheets /d/1w8cUkErljf6JzQm9q5aFwa-m9jX4o5qrAg5K7ib9Keg/edit?usp = sharing

这是我正在使用的代码:

This is the code I'm using:

function myFunction(e){
var userName = e.namedValues.Name;
var userEmail = e.namedValues.Tag;
var date = e.namedValues.Timestamp;
var subject = e.namedValues.Code;
var message = "Thanks, " + userName + " for submiting your data remember to take note of your Case number "+ subject + "You'll need this to for you or the customer to find the case again" +date;
MailApp.sendEmail (userEmail, subject, message);}

我希望它会生成电子邮件,将代码用作主题,并将其文本包含在正文中.

I expect it to generate an email, use the code as a subject and include it the text in the body.

推荐答案

不同的Google应用程序可以具有名称相同但事件对象不同的触发器.

要访问最新的表单响应,您需要触发器onFormsubmit(),它既可以是Google表格又可以是Google Form触发器.

Different Google Applications can have triggers with the same name, but different event objects.

To access the latest form response you need the trigger onFormsubmit(), which can be both a Google Sheets and Google Form trigger.

e.namedValues是Google 数据表 onFormsubmit()

e.namedValues is a Google Sheets onFormsubmit() event object, while a Google Form onFormsubmit() event object would be e.response.

您有两个选择:

  1. 将您的Apps脚本绑定到电子表格,表格响应将保存在该电子表格中,并按预期使用e.namedValues访问响应
  2. 将您的Apps脚本绑定到表单本身,并使用e.response访问响应,如下所示:
  1. Bind your Apps Script to the Spreadsheet where your form responses are being saved and access the responses with e.namedValues as intended
  2. Bind your Apps Script to the Form itself and access the responses with e.response as following:

var userName = e.response.getItemResponses()[0].getResponse();
var userEmail= e.response.getItemResponses()[1].getResponse();
...

请记住,onFormsubmit()可安装触发器.

这篇关于发出来自Google表单的响应的问题,显示错误“" TypeError:无法读取属性“值"来自未定义. (第2行,文件“代码")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆