0
votes

I have a simple script that executes on form submit. I am trying to get the .Name value which is the dropdown response to the first question on a Google Form.

I get the error:

TypeError: Cannot read property 'response' of undefined on the line var formResponse = f.response

What am I doing wrong?

    function onFormSubmit(f) {
      var formResponse = f.response;
      var itemResponses = formResponse.getItemResponses();
      var namepick = f.namedValues.Name;  // returns a string 0=name, 1=date entered, 4=hours
      var dateenter = itemResponses[1].getResponse(); // returns the date
      var hoursenter = itemResponses[4].getResponse (); // returns the hours entered
      Browser.msgBox('Name ', namepick, ' date ', dateenter, ' hours ', hoursenter); 
    }
1

1 Answers

1
votes

There are two onFormSubmits:

  1. is for the linked spreadsheet
  2. is for form

var namepick = f.namedValues.Name;

I believe you are using the event object for the form and it has no namedValues parameter.

Form Event Object

Spreadsheet Event Object