Forms Service  |  Apps Script  |  Google for Developers

This service allows scripts to create, access, and modify Google Forms.

// Create a new unpublished form, then add a checkbox question, a multiple choice question,
// a page break, then a date question and a grid of questions, then publish the form and share
// with responders.
var form = FormApp.create('New Form', /* isPublished= */ false);
var item = form.addCheckboxItem();
item.setTitle('What condiments would you like on your hot dog?');
item.setChoices([
        item.createChoice('Ketchup'),
        item.createChoice('Mustard'),
        item.createChoice('Relish')
    ]);
form.addMultipleChoiceItem()
    .setTitle('Do you prefer cats or dogs?')
    .setChoiceValues(['Cats','Dogs'])
    .showOtherOption(true);
form.addPageBreakItem()
    .setTitle('Getting to know you');
form.addDateItem()
    .setTitle('When were you born?');
form.addGridItem()
    .setTitle('Rate your interests')
    .setRows(['Cars', 'Computers', 'Celebrities'])
    .setColumns(['Boring', 'So-so', 'Interesting']);

form.setPublished(true);
form.addPublishedReaders(['user@example.com', 'group@example.com']);

Logger.log('Published URL: ' + form.getPublishedUrl());
Logger.log('Editor URL: ' + form.getEditUrl());

Classes

NameBrief description
AlignmentAn enum representing the supported types of image alignment.
CheckboxGridItemA question item, presented as a grid of columns and rows, that allows the respondent to select multiple choices per row from a sequence of checkboxes.
CheckboxGridValidationA DataValidation for a CheckboxGridItem.
CheckboxGridValidationBuilderA DataValidationBuilder for a CheckboxGridValidation.
CheckboxItemA question item that allows the respondent to select one or more checkboxes, as well as an optional "other" field.
CheckboxValidationA DataValidation for a CheckboxItem.
CheckboxValidationBuilderA DataValidationBuilder for a CheckboxValidation.
ChoiceA single choice associated with a type of Item that supports choices, like CheckboxItem, ListItem, or MultipleChoiceItem.
DateItemA question item that allows the respondent to indicate a date.
DateTimeItemA question item that allows the respondent to indicate a date and time.
DestinationTypeAn enum representing the supported types of form-response destinations.
DurationItemA question item that allows the respondent to indicate a length of time.
FeedbackTypeAn enum representing the supported types of feedback.
FormA form that contains overall properties and items.
FormAppAllows a script to open an existing Form or create a new one.
FormResponseA response to the form as a whole.
GridItemA question item, presented as a grid of columns and rows, that allows the respondent to select one choice per row from a sequence of radio buttons.
GridValidationA DataValidation for a GridItem.
GridValidationBuilderA DataValidationBuilder for a GridValidation.
ImageItemA layout item that displays an image.
ItemA generic form item that contains properties common to all items, such as title and help text.
ItemResponseA response to one question item within a form.
ItemTypeAn enum representing the supported types of form items.
ListItemA question item that allows the respondent to select one choice from a drop-down list.
MultipleChoiceItemA question item that allows the respondent to select one choice from a list of radio buttons or an optional "other" field.
PageBreakItemA layout item that marks the start of a page.
PageNavigationTypeAn enum representing the supported types of page navigation.
ParagraphTextItemA question item that allows the respondent to enter a block of text.
ParagraphTextValidationA DataValidation for a ParagraphTextItem.
ParagraphTextValidationBuilderA DataValidationBuilder for a ParagraphTextValidation.
QuizFeedbackThe bean implementation of a Feedback, which contains properties common to all feedback, such as display text or links.
QuizFeedbackBuilderThe base FeedbackBuilder that contains setters for properties common to all feedback, such as display text.
RatingIconTypeAn enum representing the supported types of rating icons.
RatingItemA question item that allows the respondent to give a rating.
ScaleItemA question item that allows the respondent to choose one option from a numbered sequence of radio buttons.
SectionHeaderItemA layout item that visually indicates the start of a section.
TextItemA question item that allows the respondent to enter a single line of text.
TextValidationA DataValidation for a TextItem.
TextValidationBuilderA DataValidationBuilder for a TextValidation.
TimeItemA question item that allows the respondent to indicate a time of day.
VideoItemA layout item that displays a video.

Alignment

Properties

PropertyTypeDescription
LEFTEnumAlign the image to the left side of the form.
CENTEREnumAlign the image to the center of the form.
RIGHTEnumAlign the image to the right side of the form.

CheckboxGridItem

CheckboxGridValidation

CheckboxGridValidationBuilder

CheckboxItem

CheckboxValidation

CheckboxValidationBuilder

Choice

DateItem

DateTimeItem

DestinationType

Properties

PropertyTypeDescription
SPREADSHEETEnumA Google Sheets spreadsheet as a destination for form responses.

DurationItem

FeedbackType

Properties

PropertyTypeDescription
CORRECTEnumFeedback that is automatically displayed to respondents for a question answered correctly.
INCORRECTEnumFeedback that is automatically displayed to respondents for a question answered incorrectly.
GENERALEnumFeedback that is automatically displayed to respondents when they submit their response.

Form

FormApp

FormResponse

GridItem

GridValidation

GridValidationBuilder

ImageItem

Item

ItemResponse

ItemType

Properties

PropertyTypeDescription
CHECKBOXEnumA question item that allows the respondent to select one or more checkboxes, as well as an optional "other" field.
CHECKBOX_GRIDEnumA question item, presented as a grid of columns and rows, that allows the respondent to select multiple choices per row from a sequence of checkboxes.
DATEEnumA question item that allows the respondent to indicate a date.
DATETIMEEnumA question item that allows the respondent to indicate a date and time.
DURATIONEnumA question item that allows the respondent to indicate a length of time.
GRIDEnumA question item, presented as a grid of columns and rows, that allows the respondent to select one choice per row from a sequence of radio buttons.
IMAGEEnumA layout item that displays an image.
LISTEnumA question item that allows the respondent to select one choice from a drop-down list.
MULTIPLE_CHOICEEnumA question item that allows the respondent to select one choice from a list of radio buttons or an optional "other" field.
PAGE_BREAKEnumA layout item that marks the start of a page.
PARAGRAPH_TEXTEnumA question item that allows the respondent to enter a block of text.
RATINGEnumA question item that allows the respondent to give a rating.
SCALEEnumA question item that allows the respondent to choose one option from a numbered sequence of radio buttons.
SECTION_HEADEREnumA layout item that visually indicates the start of a section.
TEXTEnumA question item that allows the respondent to enter a single line of text.
TIMEEnumA question item that allows the respondent to indicate a time of day.
VIDEOEnumA layout item that displays a YouTube video.
FILE_UPLOADEnumA question item that lets the respondent upload a file.
UNSUPPORTEDEnumAn item that is currently not supported through APIs.

ListItem

Methods

MethodReturn typeBrief description
createChoice(value)ChoiceCreates a new choice.
createChoice(value, isCorrect)ChoiceCreates a new choice.
createChoice(value, navigationItem)ChoiceCreates a new choice with a page-navigation option that jumps to a given page-break item.
createChoice(value, navigationType)ChoiceCreates a new choice with a page-navigation option.
createResponse(response)ItemResponseCreates a new ItemResponse for this list item.
duplicate()ListItemCreates a copy of this item and appends it to the end of the form.
getChoices()Choice[]Gets all choices for an item.
getFeedbackForCorrect()QuizFeedback|nullReturns the feedback that is shown to respondents when they respond correctly to a question.
getFeedbackForIncorrect()QuizFeedback|nullReturns the feedback that is shown to respondents when they respond incorrectly to a question.
getHelpText()StringGets the item's help text (sometimes called description text for layout items like ImageItems, PageBreakItems, and SectionHeaderItems).
getId()IntegerGets the item's unique identifier.
getIndex()IntegerGets the index of the item among all the items in the form.
getPoints()IntegerReturns the point value of a gradeable item.
getTitle()StringGets the item's title (sometimes called header text, in the case of a SectionHeaderItem).
getType()ItemTypeGets the item's type, represented as an ItemType.
isRequired()BooleanDetermines whether the respondent must answer the question.
setChoiceValues(values)ListItemSets the choices for an item from an array of strings.
setChoices(choices)ListItemSets an array of choices for an item.
setFeedbackForCorrect(feedback)ListItemSets the feedback to be shown to respondents when they respond correctly to a question.
setFeedbackForIncorrect(feedback)ListItemSets the feedback to be shown to respondents when they respond incorrectly to a question.
setHelpText(text)ListItemSets the item's help text (sometimes called description text for layout items like ImageItems, PageBreakItems, and SectionHeaderItems).
setPoints(points)ListItemSets the number of points a gradeable item is worth.
setRequired(enabled)ListItemSets whether the respondent must answer the question.
setTitle(title)ListItemSets the item's title (sometimes called header text, in the case of a SectionHeaderItem).

MultipleChoiceItem

Methods

MethodReturn typeBrief description
createChoice(value)ChoiceCreates a new choice.
createChoice(value, isCorrect)ChoiceCreates a new choice.
createChoice(value, navigationItem)ChoiceCreates a new choice with a page-navigation option that jumps to a given page-break item.
createChoice(value, navigationType)ChoiceCreates a new choice with a page-navigation option.
createResponse(response)ItemResponseCreates a new ItemResponse for this multiple-choice item.
duplicate()MultipleChoiceItemCreates a copy of this item and appends it to the end of the form.
getChoices()Choice[]Gets all choices for an item.
getFeedbackForCorrect()QuizFeedback|nullReturns the feedback that is shown to respondents when they respond correctly to a question.
getFeedbackForIncorrect()QuizFeedback|nullReturns the feedback that is shown to respondents when they respond incorrectly to a question.
getHelpText()StringGets the item's help text (sometimes called description text for layout items like ImageItems, PageBreakItems, and SectionHeaderItems).
getId()IntegerGets the item's unique identifier.
getIndex()IntegerGets the index of the item among all the items in the form.
getPoints()IntegerReturns the point value of a gradeable item.
getTitle()StringGets the item's title (sometimes called header text, in the case of a SectionHeaderItem).
getType()ItemTypeGets the item's type, represented as an ItemType.
hasOtherOption()BooleanDetermines whether the item has an "other" option.
isRequired()BooleanDetermines whether the respondent must answer the question.
setChoiceValues(values)MultipleChoiceItemSets the choices for an item from an array of strings.
setChoices(choices)MultipleChoiceItemSets an array of choices for an item.
setFeedbackForCorrect(feedback)MultipleChoiceItemSets the feedback to be shown to respondents when they respond correctly to a question.
setFeedbackForIncorrect(feedback)MultipleChoiceItemSets the feedback to be shown to respondents when they respond incorrectly to a question.
setHelpText(text)MultipleChoiceItemSets the item's help text (sometimes called description text for layout items like ImageItems, PageBreakItems, and SectionHeaderItems).
setPoints(points)MultipleChoiceItemSets the number of points a gradeable item is worth.
setRequired(enabled)MultipleChoiceItemSets whether the respondent must answer the question.
setTitle(title)MultipleChoiceItemSets the item's title (sometimes called header text, in the case of a SectionHeaderItem).
showOtherOption(enabled)MultipleChoiceItemSets whether the item has an "other" option.

PageBreakItem

Methods

MethodReturn typeBrief description
duplicate()PageBreakItemCreates a copy of this item and appends it to the end of the form.
getGoToPage()PageBreakItemGets the PageBreakItem that the form will jump to after completing the page before this page break (that is, upon reaching this page break by normal linear progression through the form).
getHelpText()StringGets the item's help text (sometimes called description text for layout items like ImageItems, PageBreakItems, and SectionHeaderItems).
getId()IntegerGets the item's unique identifier.
getIndex()IntegerGets the index of the item among all the items in the form.
getPageNavigationType()PageNavigationTypeGets the type of page navigation that occurs after completing the page before this page break (that is, upon reaching this page break by normal linear progression through the form).
getTitle()StringGets the item's title (sometimes called header text, in the case of a SectionHeaderItem).
getType()ItemTypeGets the item's type, represented as an ItemType.
setGoToPage(goToPageItem)PageBreakItemSets the page to jump to after completing the page before this page break (that is, upon reaching this page break by normal linear progression through the form).
setGoToPage(navigationType)PageBreakItemSets the type of page navigation that occurs after completing the page before this page break (that is, upon reaching this page break by normal linear progression through the form).
setHelpText(text)PageBreakItemSets the item's help text (sometimes called description text for layout items like ImageItems, PageBreakItems, and SectionHeaderItems).
setTitle(title)PageBreakItemSets the item's title (sometimes called header text, in the case of a SectionHeaderItem).

Properties

PropertyTypeDescription
CONTINUEEnumContinue to the next page of the form after completing the current page.
GO_TO_PAGEEnumJump to a specified page of the form after completing the current page.
RESTARTEnumRestart the form from the beginning, without clearing answers entered so far, after completing the current page.
SUBMITEnumSubmit the form response after completing the current page.

ParagraphTextItem

ParagraphTextValidation

ParagraphTextValidationBuilder

QuizFeedback

Methods

MethodReturn typeBrief description
getLinkUrls()String[]Gets a list of the URLs associated with the Feedback.
getText()StringGets the Feedback's display text.

QuizFeedbackBuilder

RatingIconType

Properties

PropertyTypeDescription
STAREnumA star icon.
HEARTEnumA heart icon.
THUMB_UPEnumA thumb up icon.

RatingItem

ScaleItem

Methods

MethodReturn typeBrief description
createResponse(response)ItemResponseCreates a new ItemResponse for this scale item.
duplicate()ScaleItemCreates a copy of this item and appends it to the end of the form.
getGeneralFeedback()QuizFeedback|nullReturns the feedback that is shown to respondents when they respond to a gradeable question.
getHelpText()StringGets the item's help text (sometimes called description text for layout items like ImageItems, PageBreakItems, and SectionHeaderItems).
getId()IntegerGets the item's unique identifier.
getIndex()IntegerGets the index of the item among all the items in the form.
getLeftLabel()StringGets the label for the scale's lower bound, if any.
getLowerBound()IntegerGets the scale's lower bound.
getPoints()IntegerReturns the point value of a gradeable item.
getRightLabel()StringGets the label for the scale's upper bound, if any.
getTitle()StringGets the item's title (sometimes called header text, in the case of a SectionHeaderItem).
getType()ItemTypeGets the item's type, represented as an ItemType.
getUpperBound()IntegerGets the scale's upper bound.
isRequired()BooleanDetermines whether the respondent must answer the question.
setBounds(lower, upper)ScaleItemSets the scale's lower and upper bounds.
setGeneralFeedback(feedback)ScaleItemSets the feedback to be shown to respondents when they respond to a gradeable question that doesn't have a correct or incorrect answer (ie questions that require manual grading).
setHelpText(text)ScaleItemSets the item's help text (sometimes called description text for layout items like ImageItems, PageBreakItems, and SectionHeaderItems).
setLabels(lower, upper)ScaleItemSets labels for the scale's lower and upper bounds.
setPoints(points)ScaleItemSets the number of points a gradeable item is worth.
setRequired(enabled)ScaleItemSets whether the respondent must answer the question.
setTitle(title)ScaleItemSets the item's title (sometimes called header text, in the case of a SectionHeaderItem).

TextItem

TextValidation

TextValidationBuilder

TimeItem

VideoItem