Class FormApp

  • TheFormApp service allows scripts to open existing forms or create new ones.

  • You can open a form using its ID or URL.

  • You can create a new form by providing a title, and optionally specify if it should be published.

  • TheFormApp provides methods to create various validation builders for form items like checkboxes, grid items, and text items.

  • You can access the UI of the form editor usinggetUi() to add custom menus, dialogs, and sidebars.

FormApp

Allows a script to open an existingForm or create a new one.

// Open a form by ID.constexistingForm=FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');// Create and open a form.constnewForm=FormApp.create('Form Name');

Properties

PropertyTypeDescription
AlignmentAlignmentAn enumeration of types of image alignment.
DestinationTypeDestinationTypeAn enumeration of types of destinations that can store form responses.
FeedbackTypeFeedbackTypeAn enumeration of types of formFeedbacks.
ItemTypeItemTypeAn enumeration of types of formItems.
PageNavigationTypePageNavigationTypeAn enumeration of possible behaviors for navigating pages.
RatingIconTypeRatingIconTypeAn enumeration of rating icon typesRatingIcons

Methods

MethodReturn typeBrief description
create(title)FormCreates and returns a newForm.
create(title, isPublished)FormCreates and returns a newForm in the requested publish state.
createCheckboxGridValidation()CheckboxGridValidationBuilderReturns an instance of a CheckboxGridValidationBuilder which can be used to set validation on aCheckboxGridItem.
createCheckboxValidation()CheckboxValidationBuilderReturns an instance of a CheckboxValidationBuilder which can be used to set validation on aCheckboxItem.
createFeedback()QuizFeedbackBuilderReturns an instance of a QuizFeedbackBuilder which can be used to set feedback on a gradeableItem.
createGridValidation()GridValidationBuilderReturns an instance of a GridValidationBuilder which can be used to set validation on aGridItem.
createParagraphTextValidation()ParagraphTextValidationBuilderReturns an instance of a ParagraphTextValidationBuilder which can be used to set validation onaParagraphTextItem.
createTextValidation()TextValidationBuilderReturns an instance of a TextValidationBuilder which can be used to set validation on aTextItem.
getActiveForm()FormReturns the form to which the script iscontainer-bound.
getUi()UiReturns an instance of the form editor's user-interface environment that allows the script toadd features like menus, dialogs, and sidebars.
openById(id)FormReturns theForm with the specified ID.
openByUrl(url)FormReturns theForm with the specified URL.

Detailed documentation

create(title)

Creates and returns a newForm. Throws an exception if the given title isnullor empty.

// Create and open a form.constform=FormApp.create('Form Name');

Parameters

NameTypeDescription
titleStringThe name of the new form.

Return

Form — The new form.

Throws

Error — if the given title isnull or empty

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/forms

create(title, isPublished)

Creates and returns a newForm in the requested publish state. Throws an exception ifthe given title isnull or empty.

// Create, publish and open a form.constform=FormApp.create('Form Name',true);

Parameters

NameTypeDescription
titleStringThe name of the new form.
isPublishedBooleanWhether the form should be published.

Return

Form — The new form.

Throws

Error — if the given title isnull or empty

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/forms

createCheckboxGridValidation()

Returns an instance of a CheckboxGridValidationBuilder which can be used to set validation on aCheckboxGridItem.

Return

CheckboxGridValidationBuilder


createCheckboxValidation()

Returns an instance of a CheckboxValidationBuilder which can be used to set validation on aCheckboxItem.

Return

CheckboxValidationBuilder


createFeedback()

Returns an instance of a QuizFeedbackBuilder which can be used to set feedback on a gradeableItem.

Return

QuizFeedbackBuilder


createGridValidation()

Returns an instance of a GridValidationBuilder which can be used to set validation on aGridItem.

Return

GridValidationBuilder


createParagraphTextValidation()

Returns an instance of a ParagraphTextValidationBuilder which can be used to set validation onaParagraphTextItem.

Return

ParagraphTextValidationBuilder


createTextValidation()

Returns an instance of a TextValidationBuilder which can be used to set validation on aTextItem.

Return

TextValidationBuilder


getActiveForm()

Returns the form to which the script iscontainer-bound. To interact with forms to which thescript is not container-bound, useopenById(id) oropenByUrl(url)instead.

// Get the form to which this script is bound.constform=FormApp.getActiveForm();

Return

Form — the form to which the script is bound, ornull if the script is not bound to a form

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getUi()

Returns an instance of the form editor's user-interface environment that allows the script toadd features like menus, dialogs, and sidebars. A script can only interact with the UI for thecurrent instance of an open form editor (not the view that a respondent sees), and only if thescript isbound to the form. For moreinformation, see the guides tomenus anddialogs and sidebars.

// Add a custom menu to the active form, including a separator and a sub-menu.functiononOpen(e){FormApp.getUi().createMenu('My Menu').addItem('My menu item','myFunction').addSeparator().addSubMenu(FormApp.getUi().createMenu('My sub-menu').addItem('One sub-menu item','mySecondFunction').addItem('Another sub-menu item','myThirdFunction'),).addToUi();}

Return

Ui — an instance of this form's user-interface environment


openById(id)

Returns theForm with the specified ID. Throws an exception if the ID is invalid or theuser does not have permission to open the form.

// Open a form by ID.constform=FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');

Parameters

NameTypeDescription
idStringthe ID of the form to open

Return

Form — the form with the given ID

Throws

Error — if the given ID is invalid or the user does not have sufficient permissions

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/forms

openByUrl(url)

Returns theForm with the specified URL. Throws an exception if the URL is invalid orthe user does not have permission to open the form.

// Open a form by URL.constform=FormApp.openByUrl('https://docs.google.com/forms/d/1234567890abcdefghijklmnopqrstuvwxyz_a1b2c3/edit',);

Parameters

NameTypeDescription
urlStringthe URL of the form to open

Return

Form — the form with the given URL

Throws

Error — if the given URL is invalid or the user does not have sufficient permissions

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/forms

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.