Google表单确认脚本 [英] Google Forms Confirmation Script

查看:189
本文介绍了Google表单确认脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将确认脚本放在一起,如下所述:
http://alamoxie.com/blog/tech-tips/sending-confirmation-emails-google-docs-form/



但我总是得到这个错误代码:

  TypeError:无法从undefined读取属性values。 (第5行,确认电子邮件文件)

脚本超过标准确认的目的是有一个可以很容易地阅读和打印的表格,只需要一个页面,只显示相关信息,而不是标准的确认信息,其中包含12个页面。 我正在使用它来创建食物订单。一个请求者会选择他们想要的一个事件,提交它,然后确认电子邮件到管理员,可以打印并交给厨房拉。我已经成功地创建了一个邮件合并类型的文档,但它发送了对列表中所有内容的确认,并且我想要的是最近输入的行(因此为确认脚本)。



所以这是我的代码:

 函数onFormSubmit(e){

//第一个建立变量。通过e.values命名每个变量(电子表格中的列号)。

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];

//这些是电子邮件确认的组件

var emailTo = userEmail;
var CCAddr =admin@adminaddress.com;
var subject =食品订单请求;
var emailBody =Food Order Requisition \\\
\\\
+
Pick up Date:+ pickUp +
\\\
Pick up Time:+ pickUptime +
\\\
提交:+ submitUser +
\\\
Date提交:+ timeStamp +
\\\
\\\
Activity:+ Activity +
\\\
People: + nPeople +
\ nMeal:+ Event +
\\\
以下是+ + userEmail + $所提供的+ submitUser +所需的+ Activity + b $ b\\\
\\\
Equipment and Supplies:\\\
+ Equipment +
\\\
\\\
Drinks:\\\
+ Drinks +
\\\
\\\
Snacks :\\\
+零食+
\\\
\\\
Breakfast:\\\
+早餐+
\\\
\\\
Lunch:\\\
+午餐+
\\\
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\请求:\ n+ Notes +
\\\
\\\
处理者:___________________处理日期&时间:_________________________ Food Order Requisition;

/ **
*取消注释,用它来调试
* /
// for(var i in e .values){
// Logger.log(+ i +:+ e.values [i]);
//}

MailApp.sendEmail emailTo,subject,emailBody);


}

问题是它告诉我我的值是未定义的,我无法弄清楚为什么...任何人都可以帮助解决这个问题?

>这个脚本不能在脚本编辑器中执行,它只有在它被表单提交触发时才起作用,这就是 e (event info)获取其参数的方式。从脚本编辑器中,事件信息是 undefined ,这是合乎逻辑的,因为没有事件发生。 所以你应该测试它通过发送表单。



编辑:您必须创建一个 onFormSubmit触发器是subm itt:在此处查看文档以及这里


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/

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.

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. If lauched from the script editor the event info is undefined, which is logical since no event occurred.

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

这篇关于Google表单确认脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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