0

I have this very simple code below that I need to run when a google form associated to it has been submitted. I tried to fill-in the form and after submitting it, I checked my executions on google app script and it says "e.response is not a function."

Also, when I debugged it on App Script, it says

Cannot read property 'response' of undefined at onFormSubmit(Code:2:24)

hich I think is because it cannot retrieve any data since the form wasn't filled-in.

function onFormSubmit(e){
  var formResponse = e.response;
  
  var itemResponses = formResponse.getItemResponses();
  var email = itemResponses[0].getResponse();  
  var firstName = itemResponses[1].getResponse();
  
  MailApp.sendEmail(email, firstName+", we have received your application", "Hello, "+firstName);
  
}

Any suggestions to fix this? I need the script to run upon form submission to send like a confirmation message.

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • Is it an onFormSubmit for a spreadsheet or a form? – Cooper Jul 11 '20 at 17:00
  • Thanks for that suggestion, I'll check it out. BTW, the function is for a Google form. – Karlnikolas Alcala Jul 11 '20 at 17:05
  • UPDATE: I filled-in the form again and submitted it to see if the code will run upon submission. note: this is the original code and I didn't change anything Surprisingly, it worked and I received the email sent by the code! I don't know how this happened. But I'm certain that this is the same code that erred. No modifications made at all. This is funny nonetheless, I appreciated all your help! – Karlnikolas Alcala Jul 11 '20 at 17:19
  • Does the Form have a collaborator or is the Form file shared with anyone? You can put a `try/catch` into the function and log the error to Stackdriver. – Alan Wells Jul 11 '20 at 21:54

0 Answers0