Tuesday, 18 November 2025

Google Form - cleanse question titles

The following Google Apps Script provides a way to help clean data submitted by a Google Form (via an 'onFormSubmit' trigger), specifically the question titles. We typically use the question titles in our Apps Script code to extract the specific values we want e.g. email address, name, etc. Doing so locks us into ensuring we copy the relevant question title explicitly as it is written in the Form, such as any upper/lower case characters and trailing whitespace. Any deviation from this and the automation will no longer work.

This specific piece of Apps Script has been created so that it can be easily dropped into the beginning of your existing code, to set the Form question titles all to lowercase and to remove any whitespace around them.

Google Form - cleanse question titles sample code

The Code

Make sure you have your 'onFormSubmit' trigger created as normal.

The Function 'cleanseData(originalNamedValues)' is what does the work here for you and simply needs to be called by your Parent Function, with the 'e.namedValues' passed into it. It will automatically go through every question on your Form.

Going forwards you will need to use the new all-lowercase, trimmed, question titles to get your values from the submitted Form data. There are examples of this at the bottom of the 'getFormData(e)' Function.

Spelling mistakes still matter. This code will not correct them. Similarly if you change the wording of a question you will still need to update this in your code.


Download

Google Form - cleanse question titles download (please make a copy for your own version).


No comments:

Post a Comment