Class FormApp Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The
FormAppservice 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.
The
FormAppprovides 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 using
getUi()to add custom menus, dialogs, and sidebars.
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
| Property | Type | Description |
|---|---|---|
Alignment | Alignment | An enumeration of types of image alignment. |
Destination | Destination | An enumeration of types of destinations that can store form responses. |
Feedback | Feedback | An enumeration of types of formFeedbacks. |
Item | Item | An enumeration of types of formItems. |
Page | Page | An enumeration of possible behaviors for navigating pages. |
Rating | Rating | An enumeration of rating icon typesRating |
Methods
| Method | Return type | Brief description |
|---|---|---|
create(title) | Form | Creates and returns a newForm. |
create(title, isPublished) | Form | Creates and returns a newForm in the requested publish state. |
create | Checkbox | Returns an instance of a CheckboxGridValidationBuilder which can be used to set validation on aCheckbox. |
create | Checkbox | Returns an instance of a CheckboxValidationBuilder which can be used to set validation on aCheckbox. |
create | Quiz | Returns an instance of a QuizFeedbackBuilder which can be used to set feedback on a gradeableItem. |
create | Grid | Returns an instance of a GridValidationBuilder which can be used to set validation on aGrid. |
create | Paragraph | Returns an instance of a ParagraphTextValidationBuilder which can be used to set validation onaParagraph. |
create | Text | Returns an instance of a TextValidationBuilder which can be used to set validation on aText. |
get | Form | Returns the form to which the script iscontainer-bound. |
get | Ui | Returns an instance of the form editor's user-interface environment that allows the script toadd features like menus, dialogs, and sidebars. |
open | Form | Returns theForm with the specified ID. |
open | Form | Returns 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
| Name | Type | Description |
|---|---|---|
title | String | The 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
| Name | Type | Description |
|---|---|---|
title | String | The name of the new form. |
is | Boolean | Whether 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 aCheckbox.
Return
createCheckboxValidation()
Returns an instance of a CheckboxValidationBuilder which can be used to set validation on aCheckbox.
Return
createFeedback()
Returns an instance of a QuizFeedbackBuilder which can be used to set feedback on a gradeableItem.
Return
createGridValidation()
Returns an instance of a GridValidationBuilder which can be used to set validation on aGrid.
Return
createParagraphTextValidation()
Returns an instance of a ParagraphTextValidationBuilder which can be used to set validation onaParagraph.
Return
createTextValidation()
Returns an instance of a TextValidationBuilder which can be used to set validation on aText.
Return
getActiveForm()
Returns the form to which the script iscontainer-bound. To interact with forms to which thescript is not container-bound, useopen oropeninstead.
// 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.currentonlyhttps://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
| Name | Type | Description |
|---|---|---|
id | String | the 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
| Name | Type | Description |
|---|---|---|
url | String | the 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.