Class Form

フォーム

全体的なプロパティとアイテムを含むフォーム。プロパティには、タイトル、設定、レスポンスの保存場所が含まれます。アイテムにはチェックボックスやラジオボタンなどの質問アイテムが含まれ、レイアウト アイテムは改ページなどを指します。フォームは「FormApp」からアクセスと作成が可能です。

// Open a form by ID and create a new spreadsheet.
var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
var ss = SpreadsheetApp.create('Spreadsheet Name');

// Update form properties via chaining.
form.setTitle('Form Name')
    .setDescription('Description of form')
    .setConfirmationMessage('Thanks for responding!')
    .setAllowResponseEdits(true)
    .setAcceptingResponses(false);

// Update the form's response destination.
form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());

Methods

メソッド戻り値の型概要
addCheckboxGridItem()CheckboxGridItem列と行のグリッドとして表示される新しい質問項目を追加します。これにより、回答者は一連のチェックボックスから行ごとに複数の選択肢を選択できます。
addCheckboxItem()CheckboxItem回答者が 1 つ以上のチェックボックスを選択できる新しい質問項目と、オプションの「その他」フィールドを追加します。
addDateItem()DateItem回答者が日付を指定できるようにする新しい質問項目を追加します。
addDateTimeItem()DateTimeItem新しい質問項目を追加し、回答者が日時を指定できるようにします。
addDurationItem()DurationItem新しい質問項目を追加します。これにより、回答者は期間を指定できます。
addEditor(emailAddress)Form指定されたユーザーを Form の編集者のリストに追加します。
addEditor(user)Form指定されたユーザーを Form の編集者のリストに追加します。
addEditors(emailAddresses)Form指定されたユーザー配列を Form の編集者のリストに追加します。
addGridItem()GridItem列と行のグリッドに表示される新しい質問項目を追加します。これにより、回答者は一連のラジオボタンから行ごとに 1 つの選択肢を選択できます。
addImageItem()ImageItem画像を表示する新しいレイアウト アイテムを追加します。
addListItem()ListItem新しい質問項目を追加します。これにより、回答者はプルダウン リストから選択肢を 1 つ選択できます。
addMultipleChoiceItem()MultipleChoiceItem回答者がラジオボタンのリストから 1 つの選択肢またはオプションの「その他」フィールドを選択できる、新しい質問項目を追加します。
addPageBreakItem()PageBreakItemページの始点を示す新しいレイアウト アイテムを追加します。
addParagraphTextItem()ParagraphTextItem回答者がテキストのブロックを入力できる新しい質問項目を追加します。
addScaleItem()ScaleItem新しい質問項目を追加します。これにより、回答者は一連のラジオボタンから 1 つの選択肢を選択できます。
addSectionHeaderItem()SectionHeaderItemセクションの開始を視覚的に示す新しいレイアウト アイテムを追加します。
addTextItem()TextItem回答者が 1 行のテキストを入力できる新しい質問項目を追加します。
addTimeItem()TimeItem回答者が時刻を指定できる新しい質問項目を追加します。
addVideoItem()VideoItem動画を表示する新しいレイアウト アイテムを追加します。
canEditResponse()Boolean回答を送信した後に、回答を編集するためのリンクをフォームに表示するかどうかを指定します。
collectsEmail()Booleanフォームで回答者のメールアドレスを収集するかどうかを指定します。
createResponse()FormResponseフォームへの新しい回答を作成します。
deleteAllResponses()Form送信したすべての回答をフォームの回答ストアから削除します。
deleteItem(index)voidフォーム内のすべてのアイテムのうち、指定されたインデックスにあるアイテムを削除します。
deleteItem(item)void指定した項目を削除します。
deleteResponse(responseId)Formフォームの回答ストアから 1 つの回答を削除します。
getConfirmationMessage()Stringフォームの確認メッセージを取得します。
getCustomClosedFormMessage()Stringフォームが回答を受け付けていない場合に表示されるカスタム メッセージを取得します。カスタム メッセージが設定されていない場合は空の文字列を取得します。
getDescription()Stringフォームの説明を取得します。
getDestinationId()Stringフォームの回答先の ID を取得します。
getDestinationType()DestinationTypeフォームの回答先の種類を取得します。
getEditUrl()Stringフォームの編集モードへのアクセスに使用できる URL を取得します。
getEditors()User[]この Form の編集者のリストを取得します。
getId()Stringフォームの ID を取得します。
getItemById(id)Item指定された ID を持つアイテムを取得します。
getItems()Item[]フォーム内のすべてのアイテムの配列を取得します。
getItems(itemType)Item[]指定された型のすべての項目の配列を取得します。
getPublishedUrl()Stringフォームへの回答に使用できる URL を取得します。
getResponse(responseId)FormResponseレスポンス ID に基づいて、単一のフォームのレスポンスを取得します。
getResponses()FormResponse[]フォームのすべての回答の配列を取得します。
getResponses(timestamp)FormResponse[]指定した日時以降のフォームのすべての回答の配列を取得します。
getShuffleQuestions()Booleanフォームの各ページにおける質問の順序をランダム化するかどうかを指定します。
getSummaryUrl()Stringフォームの回答の概要を表示する場合に使用できる URL を取得します。
getTitle()Stringフォームのタイトルを取得します。
hasLimitOneResponsePerUser()Booleanフォームの回答者 1 人につき回答を 1 つだけ許可するかどうかを決定します。
hasProgressBar()Booleanフォームに進行状況バーを表示するかどうかを指定します。
hasRespondAgainLink()Boolean回答者がフォームへの入力を完了した後に、別の回答を送信するためのリンクをフォームに表示するかどうかを指定します。
isAcceptingResponses()Booleanフォームが現在回答を受け付けているかどうかを示します。
isPublishingSummary()Boolean回答者がフォームへの入力を完了した後に、回答の概要を表示するリンクをフォームに表示するかどうかを指定します。
isQuiz()Booleanフォームがクイズかどうかを判断します。
moveItem(from, to)Itemフォーム内のすべてのアイテムのうち、特定のインデックスにあるアイテムを別の特定のインデックスに移動します。
moveItem(item, toIndex)Itemフォーム内のすべてのアイテムの中で、指定されたアイテムを特定のインデックスに移動します。
removeDestination()Form現在の回答先からフォームのリンクを解除します。
removeEditor(emailAddress)FormForm の編集者のリストから指定されたユーザーを削除します。
removeEditor(user)FormForm の編集者のリストから指定されたユーザーを削除します。
requiresLogin()Booleanフォームに回答する前に、同じドメインまたはサブドメインのアカウントにログインすることを要求するかどうかを指定します。
setAcceptingResponses(enabled)Formフォームが現在回答を受け付けているかどうかを設定します。
setAllowResponseEdits(enabled)Form回答を送信した後に、回答を編集するためのリンクをフォームに表示するかどうかを設定します。
setCollectEmail(collect)Formフォームで回答者のメールアドレスを収集するかどうかを設定します。
setConfirmationMessage(message)Formフォームの確認メッセージを設定します。
setCustomClosedFormMessage(message)Formフォームが回答を受け付けていない場合に表示するメッセージを設定します。
setDescription(description)Formフォームの説明を設定します。
setDestination(type, id)Formフォームの回答の保存先を設定します。
setIsQuiz(enabled)Formフォームがクイズかどうかを設定します。
setLimitOneResponsePerUser(enabled)Formフォームで回答者につき 1 つの回答のみを許可するかどうかを設定します。
setProgressBar(enabled)Formフォームに進行状況バーを表示するかどうかを設定します。
setPublishingSummary(enabled)Form回答者がフォームを送信した後に、回答の概要を表示するリンクをフォームに表示するかどうかを設定します。
setRequireLogin(requireLogin)Formフォームに回答する前に、同じドメインまたはサブドメインのアカウントにログインすることを要求するかどうかを設定します。
setShowLinkToRespondAgain(enabled)Form回答者がフォームへの入力を完了した後に、別の回答を送信するためのリンクをフォームに表示するかどうかを設定します。
setShuffleQuestions(shuffle)Formフォームの各ページの質問の順序をランダムに設定するかどうかを設定します。
setTitle(title)Formフォームのタイトルを設定します。
shortenFormUrl(url)String形式の長い URL を短縮 URL に変換します。
submitGrades(responses)Form指定された FormResponse の成績を送信します。

詳細なドキュメント

addCheckboxGridItem()

列と行のグリッドとして表示される新しい質問項目を追加します。これにより、回答者は一連のチェックボックスから行ごとに複数の選択肢を選択できます。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds a checkbox grid item.
const item = form.addCheckboxGridItem();

// Sets the title 'Where did you celebrate New Year's?'
item.setTitle('Where did you celebrate New Year's?');

// Sets the grid's rows and columns.
item.setRows(['New York', 'San Francisco', 'London'])
  .setColumns(['2014', '2015', '2016', '2017']);

リターン

CheckboxGridItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addCheckboxItem()

回答者が 1 つ以上のチェックボックスを選択できる新しい質問項目と、オプションの「その他」フィールドを追加します。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds a checkbox item.
const item = form.addCheckboxItem();

// Sets the title of the checkbox item to 'Do you prefer cats or dogs?'
item.setTitle('Do you prefer cats or dogs?');

// Sets the choices.
item.setChoiceValues(['Cats', 'Dogs']);

リターン

CheckboxItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addDateItem()

回答者が日付を指定できる新しい質問項目を追加します。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds a date item.
const item = form.addDateItem();

// Sets the title to 'When were you born?'
item.setTitle('When were you born?');

// Sets the description for the date item.
item.setHelpText('Some helper text.');

リターン

DateItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addDateTimeItem()

回答者が日時を指定できるようにする新しい質問項目を追加します。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds a question with date and time inputs.
const item = form.addDateTimeItem();

// Sets the title to 'When were you born?'
item.setTitle('When were you born?');

// Sets the question as required.
item.setRequired(true);

リターン

DateTimeItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addDurationItem()

新しい質問項目を追加します。これにより、回答者は回答時間を指定できます。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds a question with a duration input.
const item = form.addDurationItem();

// Sets the title to 'How long can you hold your breath?'
item.setTitle('How long can you hold your breath?');

// Sets the question as required.
item.setRequired(true);

リターン

DurationItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addEditor(emailAddress)

指定されたユーザーを Form の編集者のリストに追加します。ユーザーがすでに閲覧者のリストに含まれている場合、このメソッドでは閲覧者のリストでそのユーザーが除外されます。

パラメータ

名前説明
emailAddressString追加するユーザーのメールアドレス。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addEditor(user)

指定されたユーザーを Form の編集者のリストに追加します。ユーザーがすでに閲覧者のリストに含まれている場合、このメソッドでは閲覧者のリストでそのユーザーが除外されます。

パラメータ

名前説明
userUser追加するユーザーの表現。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addEditors(emailAddresses)

指定されたユーザー配列を Form の編集者のリストに追加します。いずれかのユーザーがすでに閲覧者のリストに含まれている場合、このメソッドでは閲覧者のリストから除外されます。

パラメータ

名前説明
emailAddressesString[]追加するユーザーのメールアドレスの配列。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addGridItem()

列と行のグリッドに表示される新しい質問項目を追加します。これにより、回答者は一連のラジオボタンから行ごとに 1 つの選択肢を選択できます。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds a multiple choice grid.
const item = form.addGridItem();

// Sets the title to 'Rate your interests.'
item.setTitle('Rate your interests');

// Sets the grid's rows and columns.
item.setRows(['Cars', 'Computers', 'Celebrities'])
  .setColumns(['Boring', 'So-so', 'Interesting']);

リターン

GridItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addImageItem()

画像を表示する新しいレイアウト アイテムを追加します。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds an image item.
const item = form.addImageItem();

// Gets the Google icon to use as the image.
const img = UrlFetchApp.fetch('https://fonts.gstatic.com/s/i/productlogos/googleg/v6/web-24dp/logo_googleg_color_1x_web_24dp.png');

// Sets the image, title, and description for the item.
item.setTitle('Google icon').setHelpText('Google icon').setImage(img);

リターン

ImageItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addListItem()

新しい質問項目を追加します。これにより、回答者はプルダウン リストから選択肢を 1 つ選択できます。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds a dropdown list to the form.
const item = form.addListItem();

// Sets the title to 'Do you prefer cats or dogs?'
item.setTitle('Do you prefer cats or dogs?');

// Sets the description to 'This is description text...'
item.setHelpText('This is description text...');

// Creates and adds choices to the dropdown list.
item.setChoices([
  item.createChoice('dog'),
  item.createChoice('cat')
]);

リターン

ListItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addMultipleChoiceItem()

新しい質問項目を追加します。これにより、回答者はラジオボタンのリストから選択肢を 1 つ選択するか、オプションの「その他」フィールドを選択できます。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds a multiple choice item to the form.
const item = form.addMultipleChoiceItem();

// Sets the title.
item.setTitle('What is your favorite ice cream flavor?');

// Creates some choice items.
const vanilla = item.createChoice('vanilla');
const chocolate = item.createChoice('chocolate');
const strawberry = item.createChoice('strawberry');

// Sets the choices.
item.setChoices([vanilla, chocolate, strawberry]);

リターン

MultipleChoiceItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addPageBreakItem()

ページの始点を示す新しいレイアウト アイテムを追加します。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds page break items to create a second and third page for the form.
const pageTwo = form.addPageBreakItem();
const pageThree = form.addPageBreakItem();

// Sets the titles for the pages.
pageTwo.setTitle('Page two');
pageThree.setTitle('Page three');

// Upon completion of the first page, sets the form to navigate to the third page.
pageTwo.setGoToPage(pageThree);

// Upon completion of the second page, sets the form to navigate back to the first page.
pageThree.setGoToPage(FormApp.PageNavigationType.RESTART);

リターン

PageBreakItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addParagraphTextItem()

回答者がテキストのブロックを入力できる新しい質問項目を追加します。

// Opens the form by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds the paragraph text item.
const item = form.addParagraphTextItem();

// Sets the title to 'What is your address?'
item.setTitle('What is your address?');

リターン

ParagraphTextItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addScaleItem()

新しい質問項目を追加します。これにより、回答者は一連のラジオボタンから 1 つの選択肢を選択できます。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds the scale item.
const item = form.addScaleItem();

// Sets the title of the scale item to 'Choose a number.'
item.setTitle('Choose a number');

// Sets the scale to 1-5.
item.setBounds(1, 5);

// Sets the label for the lower and upper bounds.
item.setLabels('Lowest', 'Highest');

リターン

ScaleItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addSectionHeaderItem()

セクションの開始を視覚的に示す新しいレイアウト アイテムを追加します。

 // Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds the section heading item.
const item = form.addSectionHeaderItem();

// Sets the title to 'Title of new section.'
item.setTitle('Title of new section');

// Sets the description.
item.setHelpText('Description of new section');

リターン

SectionHeaderItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addTextItem()

回答者が 1 行のテキストを入力できる新しい質問項目を追加します。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds a single-line text item.
const item = form.addTextItem();

// Sets the title to 'What is your name?'
item.setTitle('What is your name?');

リターン

TextItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addTimeItem()

回答者が時刻を指定できる新しい質問項目を追加します。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds a question with a time input.
const item = form.addTimeItem();

// Sets the title to 'What time do you usually wake up in the morning?'
item.setTitle('What time do you usually wake up in the morning?');

リターン

TimeItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

addVideoItem()

動画を表示する新しいレイアウト アイテムを追加します。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Adds a video item.
const item = form.addVideoItem();

// Sets the title, description, and video.
item.setTitle('YouTube video')
  .setHelpText('Send content automatically via Google Sheets and Apps Script')
  .setVideoUrl('https://youtu.be/xxgQr-jSu9o');

// Sets the alignment to the center.
item.setAlignment(FormApp.Alignment.CENTER);

リターン

VideoItem - 新しく作成されたアイテム。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

canEditResponse()

回答を送信した後に、回答を編集するためのリンクをフォームに表示するかどうかを指定します。

この設定にかかわらず、FormResponse.getEditResponseUrl() メソッドを使用すると、フォームの編集権限を持つユーザーは、回答の編集に使用できる URL を生成できます。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Checks if the form displays a link to edit a response after submitting it.
// The default is false. To let people edit their responses, use
// form.setAllowResponseEdits(true).
const edit = form.canEditResponse();

// If the form doesn't let people edit responses, logs false to the console.
console.log(edit);

リターン

Boolean - フォームに [回答を編集] リンクが表示されている場合は true、表示されない場合は false

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

collectsEmail()

フォームで回答者のメールアドレスを収集するかどうかを指定します。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the form to not collect respondents' email addresses.
form.setCollectEmail(false);

// Checks whether the form collects respondents' email addresses and logs it to the console.
const bool = form.collectsEmail();

console.log(bool);

リターン

Boolean - フォームでメールアドレスが収集されている場合は true、収集されていない場合は false

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

createResponse()

フォームへの新しい回答を作成します。質問アイテムに回答するには、そのアイテムから ItemResponse を作成し、FormResponse.withItemResponse(response) を呼び出してこのフォームの回答に添付します。生成されたレスポンスを保存するには、FormResponse.submit() を呼び出します。

リターン

FormResponse - 新しく作成されたフォームの回答。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

deleteAllResponses()

送信したすべての回答をフォームの回答ストアから削除します。この方法では、外部の回答先(スプレッドシートなど)に保存されている回答のコピーは削除されませんが、フォームの概要ビューはクリアされます。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

deleteItem(index)

フォーム内のすべてのアイテムのうち、指定されたインデックスにあるアイテムを削除します。指定されたインデックスにアイテムが存在しない場合、スクリプト例外をスローします。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets all the items from the form.
const items = form.getItems();

// Finds the index of a paragraph text item and deletes it by the item's index.
const index = items.findIndex(item => item.getType() === FormApp.ItemType.PARAGRAPH_TEXT);
if (index !== -1) {
  form.deleteItem(index);
}

パラメータ

名前説明
indexIntegerフォーム内のすべてのアイテムのうちのアイテムのインデックス。

例外

Error - 指定されたインデックスにアイテムが存在しない場合

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

deleteItem(item)

指定した項目を削除します。アイテムがすでに削除されている場合は、スクリプト例外をスローします。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets all of the items from the form.
const items = form.getItems();

// Finds a paragraph text item and deletes it.
const item = items.find(item => item.getType() === FormApp.ItemType.PARAGRAPH_TEXT);
if (item) {
  form.deleteItem(item);
}

パラメータ

名前説明
itemItem削除するアイテム。

例外

Error - フォームにアイテムが存在しない場合

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

deleteResponse(responseId)

フォームの回答ストアから 1 つの回答を削除します。この方法では、外部の回答先(スプレッドシートなど)に保存されている回答のコピーは削除されませんが、フォームの概要ビューから回答を削除します。レスポンス ID は FormResponse.getId() で取得できます。

パラメータ

名前説明
responseIdString削除するフォームの回答の ID。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getConfirmationMessage()

フォームの確認メッセージを取得します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the confirmation message to display after someone submits the form.
form.setConfirmationMessage('You successfully submitted the form.');

// Gets the confirmation message and logs it to the console.
const message = form.getConfirmationMessage();

console.log(message);

リターン

String - フォームの確認メッセージ。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getCustomClosedFormMessage()

フォームが回答を受け付けていない場合に表示されるカスタム メッセージを取得します。カスタム メッセージが設定されていない場合は空の文字列を取得します。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets a custom closed form message to display to the user when the form
// no longer accepts responses.
form.setCustomClosedFormMessage('The form is no longer accepting responses.');

// Gets the custom message set for the form and logs it to the console.
const message = form.getCustomClosedFormMessage();

console.log(message);

リターン

String - フォームが回答を受け付けていない場合に表示されるカスタム メッセージ。カスタム メッセージが設定されていない場合は空の文字列。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getDescription()

フォームの説明を取得します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the form description.
form.setDescription('This is the form description.');

// Gets the form description and logs it to the console.
const description = form.getDescription();

console.log(description);

リターン

String - フォームの説明。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getDestinationId()

フォームの回答先の ID を取得します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Creates a spreadsheet to use as the response destination.
const ss = SpreadsheetApp.create('Test_Spreadsheet');

// Updates the form's response destination.
form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());

// Gets the ID of the form's response destination and logs it to the console.
const destinationId = form.getDestinationId();

console.log(destinationId);

リターン

String - フォームのレスポンス先の ID。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getDestinationType()

フォームの回答先の種類を取得します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc1234556/edit');

// Gets the type of the form's response destination and logs it to the console.
const destinationType = form.getDestinationType().name();

console.log(destinationType);

リターン

DestinationType - フォームの回答の宛先のタイプ。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getEditUrl()

フォームの編集モードへのアクセスに使用できる URL を取得します。

// Opens the form by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets the URL that accesses the form's edit mode and logs it to the console.
const url = form.getEditUrl();

console.log(url);

リターン

String - フォームを編集する URL。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getEditors()

この Form の編集者のリストを取得します。

リターン

User[] - 編集権限を持つユーザーの配列。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getId()

フォームの ID を取得します。

// Opens the form by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets the ID of the form and logs it to the console.
const id = form.getId();

console.log(id);

リターン

String - フォームの ID。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getItemById(id)

指定された ID を持つアイテムを取得します。ID がフォーム内のアイテムに対応していない場合、null を返します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets the ID of the first item on the form.
const itemId = form.getItems()[0].getId();

// Gets the item from the ID.
const item = form.getItemById(itemId);

// Gets the name of the item type and logs it to the console.
const type = item.getType().name();

console.log(type);

パラメータ

名前説明
idInteger商品アイテムの ID。

リターン

Item - 指定された ID を持つアイテム。そのアイテムがフォームに存在しない場合は null

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getItems()

フォーム内のすべての項目の配列を取得します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets the list of items in the form.
const items = form.getItems();

// Gets the type for each item and logs them to the console.
const types = items.map((item) => item.getType().name());

console.log(types);

リターン

Item[] - フォーム内のすべての項目の配列。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getItems(itemType)

指定された型のすべての項目の配列を取得します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets a list of all checkbox items on the form.
const items = form.getItems(FormApp.ItemType.CHECKBOX);

// Gets the title of each checkbox item and logs them to the console.
const checkboxItemsTitle = items.map((item) => item.asCheckboxItem().getTitle());
console.log(checkboxItemsTitle);

パラメータ

名前説明
itemTypeItemType取得するアイテムのタイプ。

リターン

Item[] - そのタイプのすべてのアイテムの配列。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getPublishedUrl()

フォームへの回答に使用できる URL を取得します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets the URL to respond to the form and logs it to the console.
const url = form.getPublishedUrl();
console.log(url);

リターン

String - フォームに応答する URL。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getResponse(responseId)

レスポンス ID に基づいて、単一のフォームのレスポンスを取得します。レスポンス ID は FormResponse.getId() から取得できます。

パラメータ

名前説明
responseIdStringフォームの回答の ID。

リターン

FormResponse - フォームの回答。

例外

Error - レスポンスが存在しない場合

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getResponses()

フォームのすべての回答の配列を取得します。

リターン

FormResponse[] - フォームのすべてのレスポンスの配列。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getResponses(timestamp)

指定した日時以降のフォームのすべての回答の配列を取得します。

パラメータ

名前説明
timestampDateフォームの回答を返す最も早い日時。

リターン

FormResponse[] - フォームの回答のリスト。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getShuffleQuestions()

フォームの各ページにおける質問の順序をランダム化するかどうかを指定します。

リターン

Boolean - フォームの各ページの質問の順序がランダムである場合は true、そうでない場合は false

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getSummaryUrl()

フォームの回答の概要を表示する場合に使用できる URL を取得します。setPublishingSummary(enabled)true に設定されていない場合は、フォームの編集権限を持つユーザーのみが URL にアクセスできます。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// Opens the form by its URL.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets the URL to view a summary of the form's responses and logs it to the console.
const url = form.getSummaryUrl();
console.log(url);

リターン

String - 回答の概要を表示する URL。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

getTitle()

フォームのタイトルを取得します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the title of the form to 'For_Testing.'
form.setTitle('For_Testing');

// Gets the title of the form and logs it to the console.
const title = form.getTitle();
console.log(title);

リターン

String - フォームのタイトル。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

hasLimitOneResponsePerUser()

フォームの回答者 1 人につき回答を 1 つだけ許可するかどうかを決定します。値が true の場合、スクリプトはフォームの回答を送信できません。

リターン

Boolean - フォームで回答者 1 人につき回答 1 件のみを許可する場合は true、そうでない場合は false

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

hasProgressBar()

フォームに進行状況バーを表示するかどうかを指定します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// Opens the form by its URL.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Displays the progress bar on the form.
form.setProgressBar(true);

// Checks if the form displays a progress bar and logs it to the console.
console.log(form.hasProgressBar());

リターン

Boolean - フォームに進行状況バーを表示する場合は true、表示しない場合は false

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

回答者がフォームへの入力を完了した後に、別の回答を送信するためのリンクをフォームに表示するかどうかを指定します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the form to display a link to submit another
// response after someone submits the form.
form.setShowLinkToRespondAgain(true);

// Checks if the form displays a 'Submit another response' link and logs it to the console.
console.log(form.hasRespondAgainLink());

リターン

Boolean - フォームに「別の回答を送信」リンクが表示される場合は true、表示されない場合は false

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

isAcceptingResponses()

フォームが現在回答を受け付けているかどうかを示します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the form to accept responses.
form.setAcceptingResponses(true);

// Checks if the form is accepting responses or not and logs it to the console.
const accepting = form.isAcceptingResponses();
console.log(accepting);

リターン

Boolean - フォームが回答を受け付けている場合は true、そうでない場合は false

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

isPublishingSummary()

回答者がフォームへの入力を完了した後に、回答の概要を表示するリンクをフォームに表示するかどうかを指定します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the form to display a link to a summary of
// the responses after someone submits the form.
form.setPublishingSummary(true);

// Checks if the form displays a "See previous responses" link and logs it to the console.
const publishingLink = form.isPublishingSummary();
console.log(publishingLink);

リターン

Boolean - フォームに「前の回答を表示」リンクが表示される場合は true、表示されない場合は false

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

isQuiz()

フォームがクイズかどうかを判断します。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the form as a quiz.
form.setIsQuiz(true);

// Checks if the form is a quiz or not and logs it to the console.
console.log(form.isQuiz());

リターン

Boolean - フォームが回答を受け付けている場合は true、そうでない場合は false

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

moveItem(from, to)

フォーム内のすべてのアイテムのうち、特定のインデックスにあるアイテムを別の特定のインデックスに移動します。to インデックスが範囲外の場合、スクリプティング例外をスローします。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Moves the first item to be the last item.
form.moveItem(0, form.getItems().length - 1);

パラメータ

名前説明
fromIntegerフォーム内のすべてのアイテムのうち、アイテムの現在のインデックス。
toIntegerフォーム内のすべてのアイテムのうち、アイテムの新しいインデックス。

リターン

Item - 移動されたアイテム。

例外

Error - いずれかのインデックスが範囲外の場合。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

moveItem(item, toIndex)

フォーム内のすべてのアイテムの中で、指定されたアイテムを特定のインデックスに移動します。指定されたインデックスが範囲外の場合、スクリプト例外をスローします。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets the first item.
const item = form.getItems()[0];

// Moves the item to be the last item.
form.moveItem(item, form.getItems().length - 1);

パラメータ

名前説明
itemItem移動するアイテム。
toIndexIntegerフォーム内のすべてのアイテムのうち、アイテムの新しいインデックス。

リターン

Item - 移動されたアイテム。

例外

Error - インデックスが範囲外の場合。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

removeDestination()

現在の回答先からフォームのリンクを解除します。リンクされていない以前のデスティネーションには、以前のすべてのレスポンスのコピーが保持されます。宛先を明示的に設定していないフォームを含むすべてのフォームで、フォームのレスポンス ストアに回答のコピーを保存します。フォームに回答の送信先がない場合、このメソッドは効力を持ちません。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Opens a spreadsheet to use for the response destination.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit');

// Updates the form's response destination to the spreadsheet.
form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());

// Unlinks the form from the spreadsheet.
form.removeDestination();

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

removeEditor(emailAddress)

Form の編集者のリストから指定されたユーザーを削除します。このメソッドは、一般的なアクセス権を持つユーザーのクラスに所属するユーザーが Form にアクセスすることをブロックしません。たとえば、Form がユーザーのドメイン全体と共有されている場合や、Form がユーザーがアクセスできる共有ドライブ内にある場合です。

ドライブ ファイルの場合、閲覧者リストからもユーザーが削除されます。

パラメータ

名前説明
emailAddressString削除するユーザーのメールアドレス。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

removeEditor(user)

Form の編集者のリストから指定されたユーザーを削除します。このメソッドは、一般的なアクセス権を持つユーザーのクラスに所属するユーザーが Form にアクセスすることをブロックしません。たとえば、Form がユーザーのドメイン全体と共有されている場合や、Form がユーザーがアクセスできる共有ドライブ内にある場合です。

ドライブ ファイルの場合、閲覧者リストからもユーザーが削除されます。

パラメータ

名前説明
userUser削除するユーザーの表現。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

requiresLogin()

フォームに回答する前に、同じドメインまたはサブドメインのアカウントにログインする必要があります。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Checks if the form requires respondents to log in to a Google Workspace account
// before responding and logs it to the console.
const login = form.requiresLogin();
console.log(login);

リターン

Boolean - フォームにユーザーにログインが求められている場合は true、そうでない場合は false


setAcceptingResponses(enabled)

フォームが現在回答を受け付けているかどうかを設定します。新規フォームのデフォルトは true です。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the form to accept responses.
form.setAcceptingResponses(true);

// Checks whether the form is accepting responses or not and logs it to the console.
console.log(form.isAcceptingResponses());

パラメータ

名前説明
enabledBooleanフォームが回答を受け付ける場合は true、受け入れるしない場合は false

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setAllowResponseEdits(enabled)

回答を送信した後に、回答を編集するためのリンクをフォームに表示するかどうかを設定します。新規フォームのデフォルトは false です。

この設定にかかわらず、FormResponse.getEditResponseUrl() メソッドを使用すると、フォームの編集権限を持つスクリプト作成者は、レスポンスの編集に使用できる URL を生成できます。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Shows "Edit your response" link after someone submits the form.
form.setAllowResponseEdits(true);

// Checks whether the option to edit the form after a user submits it is set to true or not
// and logs it to the console.
console.log(form.canEditResponse());

パラメータ

名前説明
enabledBooleanフォームに [回答を編集] リンクを表示する必要がある場合は true、表示しない場合は false

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setCollectEmail(collect)

フォームで回答者のメールアドレスを収集するかどうかを設定します。新規フォームのデフォルトは false です。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the form to collect respondents' email addresses.
form.setCollectEmail(true);

// Checks whether the value is set to true or false and logs it to the console.
const collect = form.collectsEmail();
console.log(collect);

パラメータ

名前説明
collectBooleanフォームでメールアドレスを収集する場合は true、収集しない場合は false

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setConfirmationMessage(message)

フォームの確認メッセージを設定します。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets a custom confirmation message to display after someone submits the form.
form.setConfirmationMessage('Your form has been successfully submitted.');

// Gets the confirmation message set for the form and logs it to the console.
const message = form.getConfirmationMessage();
console.log(message);

パラメータ

名前説明
messageStringフォームの新しい確認メッセージです。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setCustomClosedFormMessage(message)

フォームが回答を受け付けていない場合に表示するメッセージを設定します。メッセージが設定されていない場合は、デフォルトのメッセージが使用されます。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the form to not accept responses.
form.setAcceptingResponses(false);

// Sets a custom closed form message to display to the user.
form.setCustomClosedFormMessage('The form is no longer accepting responses.');

// Gets the custom message set for the form and logs it to the console.
const message = form.getCustomClosedFormMessage();
console.log(message);

パラメータ

名前説明
messageStringフォームで回答を受け付けていない場合に表示されるメッセージ。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setDescription(description)

フォームの説明を設定します。

パラメータ

名前説明
descriptionStringフォームの新しい説明。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setDestination(type, id)

フォームの回答の保存先を設定します。送信先が明示的に設定されていないフォームを含め、すべてのフォームで、フォームのレスポンス ストアに回答のコピーを保存します。

パラメータ

名前説明
typeDestinationTypeフォームの回答先のタイプ。
idStringフォームの回答先の ID。

リターン

Form - この Form(チェーン用)。

例外

Error - 指定されたリンク先 ID が無効な場合

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setIsQuiz(enabled)

フォームがクイズかどうかを設定します。新規フォームのデフォルトは false です。

採点済みの質問はクイズでのみ使用できます。そのため、これを false に設定すると、すべての採点オプションがすべての質問から削除されます。

テストの設定は、新しいフォーム UI でのみ使用できます。フォームをテストに変換すると、新しい UI が使用されます。

// Opens the Forms file by its URL. If you created your script from within a
// Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Makes the form a quiz.
form.setIsQuiz(true);

// Checks whether the form is a quiz or not and logs it to the console.
console.log(form.isQuiz());

パラメータ

名前説明
enabledBooleanフォームに対してクイズ機能を有効にする場合は true、そうでない場合は false

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setLimitOneResponsePerUser(enabled)

フォームで回答者につき 1 つの回答のみを許可するかどうかを設定します。新規フォームのデフォルトは false です。この値を true に設定した場合、スクリプトはフォームのレスポンスを送信できません。

パラメータ

名前説明
enabledBooleanフォームで回答者 1 人につき回答 1 件のみを許可する場合は true、そうでない場合は false

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setProgressBar(enabled)

フォームに進行状況バーを表示するかどうかを設定します。新規フォームのデフォルトは false です。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Displays the progress bar on the form.
form.setProgressBar(true);

// Checks whether the form has a progress bar and logs it to the console.
console.log(form.hasProgressBar());

パラメータ

名前説明
enabledBooleanフォームに進行状況バーを表示する場合は true、表示されない場合は false

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setPublishingSummary(enabled)

回答者がフォームを送信した後に、回答の概要を表示するリンクをフォームに表示するかどうかを設定します。新規フォームのデフォルトは false です。

パラメータ

名前説明
enabledBooleanフォームに「以前の回答を表示」リンクを表示する必要がある場合は true、そうでない場合は false

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setRequireLogin(requireLogin)

フォームに回答する前に、同じドメインまたはサブドメインのアカウントにログインすることを要求するかどうかを設定します。ドメイン管理者が変更しない限り、新しいフォームのデフォルトは false です。

この機能は、Google Workspace ユーザーが作成したフォームでのみご利用いただけます。その他の種類の Google アカウントのユーザーにログインを要求することはできません。

// Opens the Forms file by its URL. If you created your script from within
// a Google Forms file, you can use FormApp.getActiveForm() instead.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Sets the form so that users must log in to their Google Workspace account.
form.setRequireLogin(true);

// Checks whether the form requires login or not and logs it to the console.
console.log(form.requiresLogin());

パラメータ

名前説明
requireLoginBooleanフォームにユーザーにログインが求められている場合は true、そうでない場合は false

リターン

Form - 現在の形式(チェーンの場合)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setShowLinkToRespondAgain(enabled)

回答者がフォームへの入力を完了した後に、別の回答を送信するためのリンクをフォームに表示するかどうかを設定します。新規フォームのデフォルトは true です。

パラメータ

名前説明
enabledBooleanフォームに「別の回答を送信」リンクを表示する必要がある場合は true、表示しない場合は false

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setShuffleQuestions(shuffle)

フォームの各ページの質問の順序をランダムに設定するかどうかを設定します。

パラメータ

名前説明
shuffleBooleanフォームの各ページの質問の順序をランダム化する必要がある場合は true、そうでない場合は false

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

setTitle(title)

フォームのタイトルを設定します。

パラメータ

名前説明
titleStringフォームの新しいタイトル。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

shortenFormUrl(url)

形式の長い URL を短縮 URL に変換します。長い URL が Google フォームに属していない場合は、例外がスローされます。

パラメータ

名前説明
urlString短縮する URL です。

リターン

String - http://goo.gl/forms/1234 形式の URL。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

submitGrades(responses)

指定された FormResponse の成績を送信します。

コードに onFormSubmit トリガーが含まれている場合、submitGrades() を呼び出すと onFormSubmit 条件がトリガーされ、無限ループが発生します。無限ループを回避するには、submitGrades() を呼び出す前に成績がすでに存在するかどうかを確認するコードを追加します。

パラメータ

名前説明
responsesFormResponse[]フォームのすべてのレスポンスの配列。

リターン

Form - この Form(チェーン用)。

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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