0

With regard to this post, when more questions are added, to the same or different page, only the last question is correctly displayed. The other questions just show the structure (e.g. multiple choices, lists). The following code shows the problem:

function createForm() {
var title = 'Multipage Form Test';
var description = 'Stackoverflow question 17083500';

var form = FormApp.create('Questionnaire')
  .setDescription('Questionnaire')
  .setConfirmationMessage('Thanks for responding!');

var page1 = form.addPageBreakItem()
  .setTitle('First page');
var item = form.addMultipleChoiceItem();
var item = form.addListItem();
var item = form.addMultipleChoiceItem();
var page2 = form.addPageBreakItem()
  .setTitle('Second page');
var item = form.addMultipleChoiceItem();
var page3 = form.addPageBreakItem()
  .setTitle('Third page');

item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes'),
     item.createChoice('No')
   ]);

item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes',page2),
     item.createChoice('No',page3)
   ]);

item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes'),
     item.createChoice('No')
   ]);

item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes'),
     item.createChoice('No')
   ]);

Logger.log(form.getEditUrl());
Logger.log(form.getPublishedUrl());
}

How is it possible to assign and display the questions to pages correctly?

Thanks a lot for your answer, sofia p.

Community
  • 1
  • 1

1 Answers1

0

Just needed to set the item choices immediately after adding each new item to the current page. All the choices were set / reassigned on just 1 item, after creating page 3.

var item = form.addMultipleChoiceItem();
item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes'),
     item.createChoice('No')
   ]);

var item = form.addListItem();
item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes',page2),
     item.createChoice('No',page3)
   ]);

var item = form.addMultipleChoiceItem();
item.setTitle('Question')
  .setChoices([
     item.createChoice('Yes'),
     item.createChoice('No')
   ]);
Bryan P
  • 5,031
  • 3
  • 30
  • 44
  • Thanks BryanP! However this is exactly the problem, the order of questions and choices. The working example in the answer to the post I quote above works just fine, but if you add other questions to page1, page2 or page3, the form you obtain does not look fine. Even if I add the items to each current page, the result I get is a form which does not look corretly... I'd be grateful if you could reply with a complete working example. – Sofia Pagliarin Jan 11 '15 at 12:38
  • You were adding them without setting the choices. What happens when you implement the code I supplied in my answer? – Bryan P Jan 11 '15 at 17:15