Interface Item

Item

A generic form item that contains properties common to all items, such as title and help text. Items can be accessed or created from a Form.

To operate on type-specific properties, use getType() to check the item's ItemType, then cast the item to the appropriate class using a method like asCheckboxItem().

 // Create a new form and add a text item.
 var form = FormApp.create('Form Name');
 form.addTextItem();

 // Access the text item as a generic item.
 var items = form.getItems();
 var item = items[0];

 // Cast the generic item to the text-item class.
 if (item.getType() == 'TEXT') {
   var textItem = item.asTextItem();
   textItem.setRequired(false);
 }
 

Implementing classes

NameBrief description

Methods

MethodReturn typeBrief description
asCheckboxGridItem()CheckboxGridItemReturns the item as a checkbox grid item.
asCheckboxItem()CheckboxItemReturns the item as a checkbox item.
asDateItem()DateItemReturns the item as a date item.
asDateTimeItem()DateTimeItemReturns the item as a date-time item.
asDurationItem()DurationItemReturns the item as a duration item.
asGridItem()GridItemReturns the item as a grid item.
asImageItem()ImageItemReturns the item as an image item.
asListItem()ListItemReturns the item as a list item.
asMultipleChoiceItem()MultipleChoiceItemReturns the item as a multiple-choice item.
asPageBreakItem()PageBreakItemReturns the item as a page-break item.
asParagraphTextItem()ParagraphTextItemReturns the item as a paragraph-text item.
asScaleItem()ScaleItemReturns the item as a scale item.
asSectionHeaderItem()SectionHeaderItemReturns the item as a section-header item.
asTextItem()TextItemReturns the item as a text item.
asTimeItem()TimeItemReturns the item as a time item.
asVideoItem()VideoItemReturns the item as a video item.
duplicate()ItemCreates a copy of this item and appends it to the end of 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.
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.
setHelpText(text)ItemSets the item's help text (sometimes called description text for layout items like ImageItems, PageBreakItems, and SectionHeaderItems).
setTitle(title)ItemSets the item's title (sometimes called header text, in the case of a SectionHeaderItem).

Detailed documentation

asCheckboxGridItem()

Returns the item as a checkbox grid item. Throws a scripting exception if the ItemType was not already CHECKBOX_GRID.

Return

CheckboxGridItem — the checkbox grid item


asCheckboxItem()

Returns the item as a checkbox item. Throws a scripting exception if the ItemType was not already CHECKBOX.

Return

CheckboxItem — the checkbox item


asDateItem()

Returns the item as a date item. Throws a scripting exception if the ItemType was not already DATE.

Return

DateItem — the date item


asDateTimeItem()

Returns the item as a date-time item. Throws a scripting exception if the ItemType was not already DATETIME.

Return

DateTimeItem — the date-time item


asDurationItem()

Returns the item as a duration item. Throws a scripting exception if the ItemType was not already DURATION.

Return

DurationItem — the duration item


asGridItem()

Returns the item as a grid item. Throws a scripting exception if the ItemType was not already GRID.

Return

GridItem — the grid item


asImageItem()

Returns the item as an image item. Throws a scripting exception if the ItemType was not already IMAGE.

Return

ImageItem — the image item


asListItem()

Returns the item as a list item. Throws a scripting exception if the ItemType was not already LIST.

Return

ListItem — the list item


asMultipleChoiceItem()

Returns the item as a multiple-choice item. Throws a scripting exception if the ItemType was not already MULTIPLE_CHOICE.

Return

MultipleChoiceItem — the multiple-choice item


asPageBreakItem()

Returns the item as a page-break item. Throws a scripting exception if the ItemType was not already PAGE_BREAK.

Return

PageBreakItem — the page-break item


asParagraphTextItem()

Returns the item as a paragraph-text item. Throws a scripting exception if the ItemType was not already PARAGRAPH_TEXT.

Return

ParagraphTextItem — the paragraph-text item


asScaleItem()

Returns the item as a scale item. Throws a scripting exception if the ItemType was not already SCALE.

Return

ScaleItem — the scale item


asSectionHeaderItem()

Returns the item as a section-header item. Throws a scripting exception if the ItemType was not already SECTION_HEADER.

Return

SectionHeaderItem — the section-header item


asTextItem()

Returns the item as a text item. Throws a scripting exception if the ItemType was not already TEXT.

Return

TextItem — the text item


asTimeItem()

Returns the item as a time item. Throws a scripting exception if the ItemType was not already TIME.

Return

TimeItem — the time item


asVideoItem()

Returns the item as a video item. Throws a scripting exception if the ItemType was not already VIDEO.

Return

VideoItem — the video item


duplicate()

Creates a copy of this item and appends it to the end of the form.

Return

Item — a duplicate of this Item, for chaining


getHelpText()

Gets the item's help text (sometimes called description text for layout items like ImageItems, PageBreakItems, and SectionHeaderItems).

Return

String — the item's help text or description text


getId()

Gets the item's unique identifier.

Return

Integer — the item's ID


getIndex()

Gets the index of the item among all the items in the form.

Return

Integer — the index of the item


getTitle()

Gets the item's title (sometimes called header text, in the case of a SectionHeaderItem).

Return

String — the item's title or header text


getType()

Gets the item's type, represented as an ItemType.

Return

ItemType — the item's type


setHelpText(text)

Sets the item's help text (sometimes called description text for layout items like ImageItems, PageBreakItems, and SectionHeaderItems).

Parameters

NameTypeDescription
textStringthe new help text

Return

Item — this Item, for chaining


setTitle(title)

Sets the item's title (sometimes called header text, in the case of a SectionHeaderItem).

Parameters

NameTypeDescription
titleStringthe new title or header text

Return

Item — this Item, for chaining

发送以下问题的反馈:

此网页
Apps Script
Apps Script