google-apps-script - 在表单提交事件对象上给出错误 : "TypeError: Cannot read property " 0"from undefined."

标签 google-apps-script google-forms

我正在尝试设置一个基本脚本,该脚本在提交表单时通过电子邮件发送,其目标是(天上掉馅饼)创建一封电子邮件,该电子邮件将发送附加的 outlook 日历邀请。这是我的脚本。

function onFormSubmit(e) {
  var userName = e.values[1];
  var userEmail = e.values[2];
  var subject = "Form Submitted";
  var message = "Thank you, " + userName + " for your submission";
  MailApp.sendEmail(userEmail, subject, message)
}

Here's an image of my trigger situation

我得到的错误是:“TypeError:无法从未定义中读取属性“0”。”

Here's an image of the Execution transcript

这是我去过的地方: Google Scripts for Sheets - onEdit and "source"

我保证我不会在编辑器中运行 - 我正在填写表格并提交。我知道我必须做一些愚蠢的事情,但我无法弄清楚它是什么。感谢您的帮助。

最佳答案

您的“提交时”触发器正在从绑定(bind)到 Form 的脚本运行,并且 values 属性不可用于发送到 的事件对象表格values 属性仅可用于发送到 电子表格 的事件对象。

查看事件对象:
Event Objects

关于google-apps-script - 在表单提交事件对象上给出错误 : "TypeError: Cannot read property " 0"from undefined.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37080745/

相关文章:

css - 无法使样式表工作

javascript - 如何使我的 'Show and hide rows' 脚本在 Google 表格中正常运行

google-apps-script - 如何使用 Google Apps 脚本将视频上传到 Youtube?

forms - 使用 Google Apps 脚本在 Google 表单中预填当前日期

r - 从 R 填写谷歌表格

google-apps-script - 发送 GET 到 space.members.list 时为 "Invalid argument"

javascript - 在 Google Apps 脚本中使用 Javascript

google-apps-script - Google Apps 脚本 : Access the form key that allows user to edit their responses

google-apps-script - 如何使用谷歌应用脚​​本重置谷歌表单计数器值

javascript - 测量填写部分的时间 - 谷歌表单