2

I found there are two ways to add a new section in Google form using pagebreakitem and sectionheaderitem in google app script which gives the same result. What is the difference between them?

Newbie
  • 31
  • 1

1 Answers1

4

Class PageBreakItem (addPageBreakItem()) and Class SectionHeaderItem (addSectionHeaderItem()) appear similar but are very different and do NOT give the same result when used in a script.

Key Differences

There key difference between the two is that PageBreakItem enables navigation from page to page. In addition, PageBreakItem can also have many section headers; whereas a SectionHeaderItem is created within a page. Each can have questions attached.

Class PageBreakItem

This example is from the Google documentation

var pageTwo = form.addPageBreakItem().setTitle('Page Two');
var pageThree = form.addPageBreakItem().setTitle('Page Three');

// Make the first two pages navigate elsewhere upon completion.
pageTwo.setGoToPage(pageThree); // At end of page one (start of page two), jump to page three
pageThree.setGoToPage(FormApp.PageNavigationType.RESTART); // At end of page two, restart form

Though the method refers to a "page", the form describes the component as a "section" - no doubt the cause of some confusion.

PageBreakItem


Class SectionHeaderItem

This example is also from the Google documentation , plus an extra section header added by me.

var item = form.addSectionHeaderItem();
item.setTitle('Title of new section');

As you can see, a new page is not created, but a section is inserted into a page.

SectionHeaderItem

Tedinoz
  • 5,911
  • 3
  • 25
  • 35
  • 1
    That's why it's confusing. In the GUI of the Google form, what means a page is referred to as a section and what means a section is referred to as a title and description. Thank you very much for your clarification. – Newbie Apr 13 '20 at 15:47
  • Yes, that's pretty right. What I didn't say is that the Page is handy for building the structure of your form; not just with navigation but grouping a-like questions into a coherent group - enabling one to build "pages of questions", so to speak. – Tedinoz Apr 13 '20 at 22:19
  • Yes. I clearly understand that a page can be a group of questions or sections. What I was trying to do is to set up the branching of the questions according to different responses. In order to do this, to my understanding, I need a page, not a section. Also, I tested to code before asking here but maybe it was my mistake during investigating the result of the code which made me confuse since I saw the page instead of section. (I didn't know why) . Anyway, I tested it again and now it makes different results as expected. So if you voted me down for asking this question, I apologize for this. – Newbie Apr 14 '20 at 09:37
  • No, I thought it was a good question. I didn't know the answer and felt compelled to test the code to establish just what the difference could be. I'm not altogether sure that this answer is as cogent and well constructed as it might be, but I couldn't see any precedent on StackOverflow, and many potential answers referred to previous versions of Forms (when it used a main menu). The outcome is confusing simply because Google continues to use the word "Section" to refer to several different components (depending on their status at any given time). – Tedinoz Apr 14 '20 at 22:52