I have created a Google Form that successfully enters user responses into a Google Sheet. I tried to create a function that would read the submitted responses when triggered by a form submit, but I can not get it to work. Here is the beginning of the function I created by following various online examples:
function onFormSubmit(e) {
//get the form responses
var formResponse = e.response;
//get an array with all the response values (values in the array are ordered as on the form)
var itemResponses = formResponse.getItemResponses();
//get the responses (array items start from 0)
var FirstName = itemResponses[0].getResponse();
var LastName = itemResponses[1].getResponse();
Here is the error message I get when it runs, which indicates the problem is with the "formResponse.getItemResponses()" statement:
TypeError: Cannot read properties of undefined (reading 'getItemResponses') at onFormSubmit(Code:7:36)
I have verified this by commenting that line out and instead defining fixed values, and the function then runs with no errors.
Here are the transcribed values for how I defined my trigger:
- Choose which function to run: onFormSubmit
- Which runs at deployment: Head
- Select event source: From spreadsheet
- Select event type: On form submit
- Failure notification settings: Notify me immediately
Can anyone see what I am doing wrong? Thanks in advance to all who respond.