4

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 = "[email protected]";
   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?

1 Answer 1

5

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

7
  • I don't receive any emails from the form/script Mar 6, 2013 at 19:28
  • did you authorize the script for mail service ? if yes, try to duplicate the Mailapp line and replace emailTo with your mail adress to check how it works. Mar 6, 2013 at 19:42
  • I authorized emails when I first played the script. I tried your new mailapp line and I still only get the google generated confirmation, but not the script generated confirmation. Mar 6, 2013 at 19:52
  • can you clarify a point : was the issue about the undefined or about the script not being executed ? it seems to me that it ends up being the 2cond ;-) please add a trigger (in ressource menu) that will create an installable onFormSubmit trigger., I'll update my answer with the relevant link. Mar 6, 2013 at 19:58
  • That Did It! Thanks! Summary: Go To Resources->All Your Triggers... Run OnFormSubmit Events From Spreadsheet > OnFormSubmit Mar 6, 2013 at 20:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.