Hi beautiful people
I'm having issues in google apps script, trying to generate a google form with several pages, one of which beeing a multiple-choice question.
I succesfully set up the routing to different sections depending of the answer to the question. The issue i'm facing is the last go-to: i need the user to be redirected out of the multiple-choice question sections after completing one section.
For now, let's say I answered with the first answer, I will be redirected to the first sub-section, but then I will have to go trough the second and third sub-sections as well, despite them beeing linked to other answers.
I want to set up a goto to the next page at the end of each subsection, to skip the other ones, but idk how.
Here is a simplified version of my current script :
// Setting up the multipleChoiceItem:
let mci = form.addMultipleChoiceItem()
.setTitle("Question")
.setRequired(true)
// Setting up the sub-sections
var sectionOne = form.addPageBreakItem()
.setTitle("First Section")
.setHelpText("This is the first section");
form.addTextItem().setTitle("Question inside section one").setRequired(true);
var sectionTwo = form.addPageBreakItem()
.setTitle("Second section")
.setHelpText("This is the second section");
form.addTextItem().setTitle("Questio inside section two").setRequired(true);
var sectionThree = form.addPageBreakItem()
.setTitle("Third section")
.setHelpText("This is the third section");
form.addTextItem().setTitle("Question inside section three").setRequired(true);
// linking the sections to the answers
mci.setChoices([
mci.createChoice("first answer", sectionOne),
mci.createChoice("second answer", sectionTwo),
mci.createChoice("third answer", sectionThree)
]);
// The next page and the rest of the form
var nextPage = form.addPageBreakItem()
.setTitle("The next page")
.setHelpText("This is the next page I would need to be redirected to after answering to any subsections of the mci");
I'm pretty sure it has something to do with pageBreakItems and GO_TO_PAGE, something that could look like this:
sectionOne.setGoToPage(FormApp.PageNavigationType.GO_TO_PAGE(nextPage));
but I can't get it to work, it seems like the GO_TO_PAGE method was never really implemented, there is little to none info about it in the doc.
Anyway, I hope that someone has figured it out, I would appreciate a little help!
Thanks a lot mates !
So thanks to Copilot i got it figured out, turns out I was pretty close, but it was pretty difficult to get it to work dued to the lack of documentation on this very topic.
This is what it would look like:
// Setting up the multipleChoiceItem:
let mci = form.addMultipleChoiceItem()
.setTitle("Question")
.setRequired(true)
// Setting up the sub-sections
var sectionOne = form.addPageBreakItem()
.setTitle("First Section")
.setHelpText("This is the first section");
form.addTextItem().setTitle("Question inside section one").setRequired(true);
var sectionTwo = form.addPageBreakItem()
.setTitle("Second section")
.setHelpText("This is the second section");
form.addTextItem().setTitle("Questio inside section two").setRequired(true);
var sectionThree = form.addPageBreakItem()
.setTitle("Third section")
.setHelpText("This is the third section");
form.addTextItem().setTitle("Question inside section three").setRequired(true);
// linking the sections to the answers
mci.setChoices([
mci.createChoice("first answer", sectionOne),
mci.createChoice("second answer", sectionTwo),
mci.createChoice("third answer", sectionThree)
]);
// The next page and the rest of the form
var nextPage = form.addPageBreakItem()
.setTitle("The next page")
.setHelpText("This is the next page I would need to be redirected to after answering to any subsections of the mci");
// [rest of the form]
// Routing to the next page after each answer section
sectionOne.setGoToPage(nextPage);
sectionTwo.setGoToPage(nextPage);
sectionThree.setGoToPage(nextPage);