我一直在努力将这里描述的确认脚本放在一起: http://alamoxie.com/blog/tech-tips/sending-confirmation-emails-google-docs-form/
但我总是得到这个错误代码:
TypeError: Cannot read property "values" from undefined. (line 5, file "Confirmation Email")
脚本相对于标准确认的目的是提供一个易于阅读和打印的表单,只需要一页只包含相关信息,而不是标准的确认书,这些页面会吐出12页。
在这种情况下,我用它来创建食物订单。请求者会选择他们想要的事件,提交它,然后电子邮件确认将发送到管理员,可以打印并交给厨房拉。我已成功制作了邮件合并类型文档,但它会对列表中的所有内容发送确认,而我想要的是输入的最新行(因此确认脚本)。
所以这是我的代码:
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);
}
问题在于它告诉我我的价值观未定义,我无法弄清楚为什么......任何人都可以帮忙吗?
答案 0 :(得分:5)
此脚本无法从脚本编辑器执行,只有在表单提交触发时才有效,这就是e
(事件信息)获取其参数的方式。如果从脚本编辑器中激活,则事件信息为undefined
,这是合乎逻辑的,因为没有发生任何事件。
所以你应该通过发送表格进行测试。
编辑:您必须创建onFormSubmit trigger
才能在提交表单时运行脚本:see doc here以及here