Google Forms is a cloud-based survey solution that comes with real-time collaboration and powerful tools to customize form questions. The information and data that you can collect from Google Forms are astounding! It has become quite versatile that its use in education keeps growing.
Let’s understand how to extend Google Form questions with the example of an international school that built a form where students can register their details. It had a drop-down list of countries, the name of teachers as multiple-choice questions, and a checkbox-style question where students can tick one or more boxes to mark their favorite subjects.
Creating such a form inside Google Forms is easy and simple but there are two issues that you might face:
In the Google-dominated world, we can easily automate adding bulk questions in Google Forms with the help of Google Scripts.
The design is simple and easy to understand. A Google Sheet, with all the answer choices for various questions in the Google Form, will act as the data source. The app will read the data from the data source (Google Sheet) to auto-populate the choices in the form with one click. There’s a way to dynamically update the form by creating a time trigger that runs every hour, day, or month and uses the most current data available in your spreadsheet.
Create a Google Spreadsheet by adding the question titles in the first row, one column each. Then, write all the options or choices available for each question. This is how your spreadsheet would look like:
Note that the column headings in the spreadsheet should exactly match the form fields in the Google Form. The Google Script can add answers in bulk as multiple-choice questions with a single answer, drop-down lists, and checkbox with multiple options.
First, open the sheet that consists of all the question choices. Then, go to the Tools menu and choose Script Editor. Replace the default code in the script editor with the Google Script below.
/** * Auto-populate Question options in Google Forms * from values in Google Spreadsheet * * Written by Amit Agarwal (MIT License) * **/ const populateGoogleForms = () => { const GOOGLE_SHEET_NAME = “<>”; const GOOGLE_FORM_ID = “<>”; const ss = SpreadsheetApp.getActiveSpreadsheet(); const [header, …data] = ss .getSheetByName(GOOGLE_SHEET_NAME) .getDataRange() .getDisplayValues(); const choices = {}; header.forEach((title, i) => { choices[title] = data.map((d) => d[i]).filter((e) => e); }); FormApp.openById(GOOGLE_FORM_ID) .getItems() .map((item) => ({ item, values: choices[item.getTitle()], })) .filter(({ values }) => values) .forEach(({ item, values }) => { switch (item.getType()) { case FormApp.ItemType.CHECKBOX: item.asCheckboxItem().setChoiceValues(values); break; case FormApp.ItemType.LIST: item.asListItem().setChoiceValues(values); break; case FormApp.ItemType.MULTIPLE_CHOICE: item.asMultipleChoiceItem().setChoiceValues(values); break; default: // ignore item } }); ss.toast(“Google Form Updated !!”); }; |
Note to replace the GOOGLE_SHEET_NAME and the GOOGLE_FORM_ID with your own values. Now go to the Run menu inside the Script editor, then choose the ‘populateGoogleForms’ function and it will instantly add the choices for all the specified questions in the Google Form if run correctly.
You can easily update the answer choices in the Google Form, whenever needed, by simply updating the value inside the spreadsheets and then running the same auto-populate function from the Script Editor.
In order to make it even simpler, you can also add a button on the spreadsheet that will automatically update the answers in Google Forms when clicked.
And you are all done! You can now click on the button to Update your Google Forms right within Google Sheets. Remember, the Script will not append the choices but will replace all existing choices with the ones available in your Google Sheet.
Leave a Reply