1
votes

I'm trying to create a google form which adapts each question based on the previous response. I realize that while google forms cannot be written dynamically, you can manually add in the option to "go to section based on answer" in the GUI editor.

My question is - is there a way to write this function go to section based on answer in a Google App Script? I will have hundreds of answers for some of my questions and it will not be possible to manually add them in. My answer choices will also be added from a google spreadsheet and automated to change every day.

Any other experiences or tips faking dynamic google forms appreciated.

1
Look through the reference documentation for the Form service. You'll find classes and methods that you can use to dynamically build questions that jump to a section based on a multiple choice answer. - TheAddonDepot

1 Answers

1
votes

I know this is old question, but as I was working on the similar problem, I am providing this answer just for reference.

You can create a new section, with desired questions, and continue on it, based only on the answers. You can use something like this code:

// Create multiple choice questionnaire
let aup = form.addMultipleChoiceItem()
    .setTitle(NEWCOMER)
    .setHelpText('Is this your first time using the App?'); 
  
  // Creates a new section
  var newcomerSection = form.addPageBreakItem()
    .setTitle(NEWCOMER_TITLE)
    .setHelpText('Please read and comply with Acceptable Use Policy');
  
  // Based on the choice, we either continue to previously created section,
  // or on the next section in line. You can also create two sections,
  // and jump in the second answer to that section.
  aup.setChoices([
    aup.createChoice('Yes', newcomerSection),
    aup.createChoice('No',FormApp.PageNavigationType.CONTINUE),
  ]);