简体   繁体   English

Google表单确认脚本

[英]Google Forms Confirmation Script

I've been trying to put together a confirmation script from as described here: http://alamoxie.com/blog/tech-tips/sending-confirmation-emails-google-docs-form/ 我一直试图整理一个如下所述的确认脚本: http//alamoxie.com/blog/tech-tips/sending-confirmation-emails-google-docs-form/

But I always get this error code: 但我总是得到这个错误代码:

TypeError: Cannot read property "values" from undefined. (line 5, file "Confirmation Email")

The purpose of the script over the standard confirmation is to have a form that can be easily read and printed out that only takes up one page with only the relevant information rather than the standard confirmation that spits out 12 pages. 脚本相对于标准确认的目的是提供一个易于阅读和打印的表单,该表单仅占用一页,仅包含相关信息,而不是标准确认书,其中有12页。

In this case I am using it to create a food order. 在这种情况下,我用它来创建食物订单。 A requester would select which items they want for an event, submit it, then an email confirmation would go to the admin that can be printed and handed to the kitchen to pull. 请求者会选择他们想要的事件,提交它,然后电子邮件确认将发送到管理员,可以打印并交给厨房拉。 I've successfully made a mail merge type document, but it sends a confirmation for everything on the list, and all I want is the most recent line entered (hence the confirmation script). 我已成功制作了邮件合并类型文档,但它会对列表中的所有内容发送确认,而我想要的是输入的最新行(因此确认脚本)。

So here's my code: 所以这是我的代码:

    function onFormSubmit(e) {

  // First establish the variables. Name each variable by the e.values (column number in the spreadsheet).

  var timeStamp = e.values[0];
  var Activity = e.values[2];
  var pickUp = e.values[3];
  var pickUptime = e.values[4];
  var nPeople = e.values[5];
  var submitUser = e.values[6];
  var Equipment = e.values[7];
  var Drinks = e.values[8];
  var Breakfast = e.values[9];
  var Lunch = e.values[10];
  var Dinner = e.values[11];
  var eveningProgram = e.values[12];  
  var Event = e.values[13];
  var Snacks = e.values[14];
  var Notes = e.values[15];
  var userEmail = e.values[17];

  // These are the components of the email confirmation

   var emailTo = userEmail;
   var CCAddr = "admin@adminaddress.com";
   var subject = "Food Order Request";
   var emailBody =  "Food Order Requisition\n\n" +
                    "Pick up Date:" + pickUp + 
                    "\nPick up Time:" + pickUptime +
                    "\nSubmitted by:" + submitUser +
                    "\nDate Submitted:" + timeStamp +
                    "\n\nActivity:" + Activity +
                    "\nPeople:" + nPeople +
                    "\nMeal:" +Event +
                    "\nThe following is needed for" + Activity + "by" + submitUser + "who can be reached at" + userEmail +
                    "\n\nEquipment and Supplies:\n" + Equipment +
                    "\n\nDrinks:\n" + Drinks +
                    "\n\nSnacks:\n" + Snacks +
                    "\n\nBreakfast:\n" + Breakfast +
                    "\n\nLunch:\n" + Lunch +
                    "\n\nDinner:\n" + Dinner +
                    "\n\nEvening Program/Special Events:\n" + eveningProgram +
                    "\n\nThe following special notes were also requested:\n" + Notes +
                    "\n\nProcessed by:___________________ Processed Date & Time:_________________________Food Order Requisition";

  /**
   * Un-comment this to use it for debugging
   */
//  for (var i in e.values) {
//    Logger.log("" + i + ":" + e.values[i]);
//  }

                    MailApp.sendEmail(emailTo, subject, emailBody);


}

The problem is it tells me my values are undefined and I can't figure out why... Can anyone help with this? 问题是它告诉我我的价值观是不确定的,我无法弄清楚为什么......任何人都可以帮忙吗?

This script cannot be executed from the script editor, it works only if it is triggered by a form submission, that's the way e (event info) gets its parameter. 此脚本无法从脚本编辑器执行,只有在表单提交触发时才有效,这就是e (事件信息)获取其参数的方式。 If lauched from the script editor the event info is undefined , which is logical since no event occurred. 如果从脚本编辑器中激活,则事件信息是undefined ,这是合乎逻辑的,因为没有发生任何事件。

So you should test it by sending forms. 所以你应该通过发送表格进行测试。

EDIT : You have to create an onFormSubmit trigger to make the script run when a form is submitted : see doc here and also here 编辑:您必须创建一个onFormSubmit trigger ,以便在提交表单时运行脚本: 请参阅此处的doc以及此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM