I have some very simple code that is triggered by a google form (see http://goo.gl/lFHi3j) that asks for 2 email addresses. The code works fine when the email address is hardcoded (see commented email below) but when I try and obtain the email using e.values (when the form is submitted) is get the following error
Execution failed: TypeError: Cannot read property "1" from undefined. (line 3, file "Code").
I've searched this forum but can't find a solution to this problem. Can anyone please help.
function onFormSubmit (e) {
// var email_address_ = "[email protected]";
var email_address_ = e.values[1];
// Send the email
var subject_ = "Andy's Report";
var body_ = "Here is Andy's report...";
MailApp.sendEmail(email_address_, subject_, body_, {htmlBody: body_});
}
There is no e.values[1]
.
That is the answer to the question as to why you are getting that error.
Do a console.log(e)
and familiarize yourself with what e
consists of by looking at the log results in a browser debugger.
From there you can determine for yourself if e.values even exists as an array. Then go from there.
Thanks for the responses which all helped me find a solution to the problems I was having. Here's what I've discovered as I've worked on a solution:
Having worked through these issues my form now works perfectly (albeit a little clumsily with all questions being compulsory). I would be very grateful if anyone has any suggestions on how to get around the Editing and and Blank Field problems.
(Thanks to TJ Houston for his original script)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With