0

I have created a form that asks the user for their name and campus mailbox number. I want to email these responses to another user when the form get submitted.

I am using this code and I don't get any emails with with responses to the form. This script is written in the google sheets that was created/linked to the form where the answers go.

I also made sure in the script editor to turn the on form submit trigger on under Edit>Current Project Triggers.

function onFormSubmit(e){
  var name = e.values[1];
  var mailbox = e.values[2];
  var subject = "New Cold Pack Order";
  var message = "New Cold Pack Order received for " + name + " to be delivered to Mailbox number " + mailbox; //email message to be sent.

  MailApp.sendEmail ("myemail@gmail.com", subject, message);
}

When I go debug the code I get this error:

TypeError: Cannot read property "values" from undefined. (line 2, file "Code")

When I hard code results and submit the form I don't get an email sent to me. WHen I hard code the script and test it in the script editor it works.

I am looking for ideas on what I need to do to get this to run or what I need to do to get this function to work properly.

Thank you!

Kos
  • 4,890
  • 9
  • 38
  • 42
  • 1
    Possible duplicate of [How can I test a trigger function in GAS?](https://stackoverflow.com/questions/16089041/how-can-i-test-a-trigger-function-in-gas) – Rubén Jan 23 '18 at 20:15

1 Answers1

0

You cannot debug the code by simply running the function as the parameter e is passed only when the form trigger runs.

Assuming that you have already associated this function with a trigger, go to the form and submit a test entry.

Then go to the script and do View > Execution Logs to see any errors.

You can also put Logger.log(e) in the function to check for the values that are passed on form submit.

Amit Agarwal
  • 10,910
  • 1
  • 32
  • 43
  • When I go into Execution Logs I see the project and function in there and they are listed as failed. The types are listed as editor. It looks like the trigger is not activating when the form is being submitted. I have triggers listed under Edit>Current projects triggers which has: Run Events onFormSubmit From spreadsheet on form submit – Spaceman Jan 25 '18 at 21:06