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?