apps script event.namedValues[] not functioning as intended

800 views
Skip to first unread message

Timothy Payn (PaynMusic)

unread,
Jun 28, 2023, 10:23:58 PM6/28/23
to Google Apps Script Community

So I've been working on a script to handle responses from one of my google forms, and for some reason, when the form submits, it doesn't define the event.namedValues properly and my script cant see the responses and returns
"TypeError: Cannot read properties of undefined (reading 'Minecraft Username:') at handleFormSubmit(Code:16:41)".

The issue at the moment seems to be the username read from response [0]. I'll post the function below, (the part that is dysfunctional. I need to protect privacy so the rest of the code is not shown). did I miss something? It's racking my brain why responses aren't visible to my app script.


function handleFormSubmit(event) {
  console.log('Form submitted'); //logs the submit action to show the trigger is functioning
    console.log(event); // Logs the event object to inspect its structure for debugging
  var playerUsername = event.namedValues["Minecraft Username:"][0]; //should pull from first response
  var serverAddress = event.namedValues['Server'][1]; //should pull from second response

Tanaike

unread,
Jun 28, 2023, 10:33:25 PM6/28/23
to Google Apps Script Community
In order to correctly understand your current situation, can I ask you about the following 2 questions?
  1. Where is your script in Google Form or Google Spreadsheet? Or, is it a standalone type?
  2. How did you run your script of "handleFormSubmit"?

Timothy Payn (PaynMusic)

unread,
Jun 29, 2023, 2:14:24 PM6/29/23
to Google Apps Script Community
@tanaike it is a stand alone script, and uses the form ID to create the trigger. run once and it creates the trigger as a listener. then when form submits, the script is triggered, and is supposed to pull the responses from the form, and organize them into a vote packet for votifier (a plugin/api for minecraft.) so that servers know what player voted for their server on my soon to be top list service.

should i have bound the script to the form? im trying to create the script so that other google sites users can use the script as a plug n play once its been completed

Tanaike

unread,
Jun 29, 2023, 9:37:49 PM6/29/23
to Google Apps Script Community
Thank you for replying. From "it is a stand alone script, and uses the form ID to create the trigger. run once and it creates the trigger as a listener.", if you are using the OnSubmit trigger of Google Form, please change the OnSubmit trigger of Google Spreadsheet. I'm worried that this might be the reason for your current issue. But, if I misunderstood your current situation from your reply, I apologize.

This thread on Stackoverflow might be useful. https://stackoverflow.com/q/43429161

About "should i have bound the script to the form?", I think that you can use the standalone type.
Reply all
Reply to author
Forward
0 new messages