Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically edit multiple choice options in live Google Form using Apps Script

I'm a high school teacher in L.A. trying to create a course registration system using Apps Script. I need the Google Form I'm using for this registration to:

Question 1) Update the choices available in subsequent multiple choice questions on new pages based on a student's current response choices.

Question 2) Eliminate choices from the form when a multiple choice option has reached it's "cap".

Question 1 Example) A student registers for “tie-tying” in workshop 1, and gets taken to a new page. The Script edits the available choices on that new page based on the student’s first choice, and removes “tie-tying” from the list of possible choices on that new page, so “etiquette” is their only remaining option.

Question 2 Example) Students can either register for “tie-tying” or “etiquette”, both responses are initially available in the Google Form. 30 students take the survey, all 30 register for the “tie-tying” workshop. The Apps Script references the response spreadsheet, realizes the “tie-tying” workshop is full, then removes it from the Google Form's list of possible choices. Student 31 goes to register, and their only option is “etiquette”.

If my question has already been asked and answered (believe me, I did search!) I'd appreciate the redirection.

like image 321
user2752213 Avatar asked Sep 05 '13 21:09

user2752213


People also ask

How do I use dynamic fields in Google Forms?

Choose Question - first go to menu item "Add-ons" --> Dynamic Fields --> Create Mapping" and select a question where you like to create a mapping to insert values dynamically. Please be aware that only questions of type Drop-down, Multiple Choice, Grid, List and Checkbox are displayed for selection.

How do I import a drop down list into Google Forms?

In your form, click on the question you want to add a dropdown list to or add a new question by clicking the plus sign in the floating menu on the right. Click the box in the upper right corner of the question field. Then select Dropdown. Now you can add items for your dropdown list by clicking Add option.


1 Answers

I believe we can achieve your second objective without too much difficulty and modify the form, based on the current state of response.

The approach is to

  1. Create the form and associate it with a response spreadsheet
  2. In that response spreadsheet, create a script with a function (updateForm for instance)
  3. Bind that function with the onFormSubmit event, see Using Container-Specific Installable Triggers.
  4. Analyse the response in the updateForm function and modify your form using the Form Service

For instance

function updateForm(e) {
  if (e.values[1] == 'Yes') {
    Logger.log('Yes');
    var existingForm = FormApp.openById('1jYHXD0TBYoKoRUI1mhY4j....yLWGE2vAm_Ux7Twk61c');
    Logger.log(existingForm);
    var item = existingForm.addMultipleChoiceItem();
     item.setTitle('Do you prefer cats or dogs?')
     .setChoices([
         item.createChoice('Cats'),
         item.createChoice('Dogs')
      ])
     .showOtherOption(true);
  }
}

When it comes to achieving the goal in your first question, its more delicate, as the form will not submit mid way. What is possible is to go to different pages based on different responses to a Multiple Choice question, your use case may fit this method, although its not very dynamic.

Further its possible to use html Service to create completely dynamic experience.

Let me know if you need further information.

like image 106
patt0 Avatar answered Oct 03 '22 04:10

patt0