全体的なプロパティと項目を含むフォーム。プロパティには、タイトル、設定、回答の保存場所が含まれます。項目には、チェックボックスやラジオボタンなどの質問項目が含まれますが、レイアウト項目にはページ分割などが含まれます。フォームには Form
からアクセスまたは作成できます。
// Open a form by ID and create a new spreadsheet.
const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
const 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());
メソッド
メソッド | 戻り値の型 | 概要 |
---|---|---|
add | Checkbox | 列と行のグリッドとして表示される新しい質問項目を追加します。回答者は、一連のチェックボックスから行ごとに複数の選択肢を選択できます。 |
add | Checkbox | 回答者が 1 つ以上のチェックボックスを選択できる新しい質問項目と、オプションの「その他」フィールドを追加します。 |
add | Date | 回答者が日付を指定できる新しい質問項目を追加します。 |
add | Date | 回答者が日時を指定できる新しい質問アイテムを追加します。 |
add | Duration | 回答者が期間を指定できる新しい質問項目を追加します。 |
add | Form | 指定されたユーザーを Form の編集者のリストに追加します。 |
add | Form | 指定されたユーザーを Form の編集者のリストに追加します。 |
add | Form | 指定されたユーザーの配列を Form の編集者のリストに追加します。 |
add | Grid | 列と行のグリッドとして表示される新しい質問アイテムを追加します。回答者は、一連のラジオボタンから行ごとに 1 つの選択肢を選択できます。 |
add | Image | 画像を表示する新しいレイアウト アイテムを追加します。 |
add | List | 回答者がプルダウン リストから 1 つの選択肢を選択できる新しい質問項目を追加します。 |
add | Multiple | 回答者がラジオボタンのリストまたはオプションの「その他」フィールドから 1 つの選択肢を選択できる新しい質問項目を追加します。 |
add | Page | ページの開始を示す新しいレイアウト アイテムを追加します。 |
add | Paragraph | 回答者がテキストのブロックを入力できる新しい質問項目を追加しました。 |
add | Rating | 回答者が評価を付けられる新しい質問項目を追加します。 |
add | Scale | 番号付きのラジオボタンの中から 1 つのオプションを選択できる新しい質問アイテムを追加します。 |
add | Section | セクションの開始を視覚的に示す新しいレイアウト アイテムを追加します。 |
add | Text | 回答者が 1 行のテキストを入力できる新しい質問項目を追加します。 |
add | Time | 回答者が時刻を指定できる新しい質問項目を追加します。 |
add | Video | 動画を表示する新しいレイアウト アイテムを追加します。 |
can | Boolean | フォームに、送信後に回答を編集するためのリンクを表示するかどうかを指定します。 |
collects | Boolean | フォームで回答者のメールアドレスを収集するかどうかを指定します。 |
create | Form | フォームに対する新しい回答を作成します。 |
delete | Form | 送信された回答をすべてフォームの回答ストアから削除します。 |
delete | void | フォーム内のすべてのアイテムのうち、指定されたインデックスのアイテムを削除します。 |
delete | void | 指定されたアイテムを削除します。 |
delete | Form | フォームの回答ストアから 1 つの回答を削除します。 |
get | String | フォームの確認メッセージを取得します。 |
get | String | フォームで回答を受け付けていない場合に表示されるカスタム メッセージを取得します。カスタム メッセージが設定されていない場合は、空の文字列を取得します。 |
get | String | フォームの説明を取得します。 |
get | String | フォームの回答の宛先の ID を取得します。 |
get | Destination | フォームの応答先のタイプを取得します。 |
get | String | フォームの編集モードにアクセスするために使用できる URL を取得します。 |
get | User[] | この Form の編集者のリストを取得します。 |
get | String | フォームの ID を取得します。 |
get | Item | 指定された ID のアイテムを取得します。 |
get | Item[] | フォーム内のすべてのアイテムの配列を取得します。 |
get | Item[] | 指定されたタイプのすべてのアイテムの配列を取得します。 |
get | String | フォームへの回答に使用できる URL を取得します。 |
get | Form | 回答 ID に基づいて 1 つのフォームの回答を取得します。 |
get | Form | フォームのすべての回答の配列を取得します。 |
get | Form | 指定した日時以降のフォームのすべての回答の配列を取得します。 |
get | Boolean | フォームの各ページの質問の順序をランダムにするかを指定します。 |
get | String | フォームの回答の概要を表示するために使用できる URL を取得します。 |
get | String | フォームのタイトルを取得します。 |
has | Boolean | フォームで回答者ごとに 1 回だけ回答できるようにするかどうかを指定します。 |
has | Boolean | フォームに進行状況バーを表示するかどうかを指定します。 |
has | Boolean | 回答者がフォームの入力を完了した後に、別の回答を送信するためのリンクをフォームに表示するかどうかを決定します。 |
is | Boolean | フォームで現在回答を受け付けているかどうかを判断します。 |
is | Boolean | 回答者がフォームの入力を完了した後に、回答の概要を表示するリンクをフォームに表示するかどうかを指定します。 |
is | Boolean | フォームがテストかどうかを判断します。 |
move | Item | フォーム内のすべての項目のうち、指定されたインデックスの項目を別の指定されたインデックスに移動します。 |
move | Item | フォーム内のすべての項目の中で、指定した項目を指定されたインデックスに移動します。 |
remove | Form | フォームと現在の回答先のリンクを解除します。 |
remove | Form | 指定されたユーザーを Form の編集者のリストから削除します。 |
remove | Form | 指定されたユーザーを Form の編集者のリストから削除します。 |
set | Form | フォームで現在回答を受け付けているかどうかを設定します。 |
set | Form | 回答を送信した後に回答を編集するためのリンクをフォームに表示するかどうかを設定します。 |
set | Form | フォームで回答者のメールアドレスを収集するかどうかを設定します。 |
set | Form | フォームの確認メッセージを設定します。 |
set | Form | フォームで回答を受け付けていない場合に表示するメッセージを設定します。 |
set | Form | フォームの説明を設定します。 |
set | Form | フォームの回答を保存する宛先を設定します。 |
set | Form | フォームがテストかどうかを設定します。 |
set | Form | フォームで回答者ごとに 1 つの回答のみを許可するかどうかを設定します。 |
set | Form | フォームに進行状況バーを表示するかどうかを設定します。 |
set | Form | 回答者がフォームを送信した後に、回答の概要を表示するリンクをフォームに表示するかどうかを設定します。 |
set | Form | 回答者がフォームの入力を完了した後に、別の回答を送信するためのリンクをフォームに表示するかどうかを設定します。 |
set | Form | フォームの各ページの質問の順序をランダムにするかを設定します。 |
set | Form | フォームのタイトルを設定します。 |
shorten | String | フォームの長い URL を短縮 URL に変換します。 |
submit | Form | 指定された FormResponse の成績を送信します。 |
サポート終了のメソッド
メソッド | 戻り値の型 | 概要 |
---|---|---|
| Boolean | 回答者が回答する前に、同じドメインまたはサブドメインのアカウントにログインすることがフォームで求められるかどうかを指定します。 |
| Form | 回答者が回答する前に、同じドメインまたはサブドメインのアカウントにログインする必要があるかどうかを設定します。 |
詳細なドキュメント
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();
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'
]);
戻る
Checkbox
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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']);
戻る
Checkbox
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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.');
戻る
Date
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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);
戻る
Date
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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);
戻る
Duration
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
addEditor(emailAddress)
addEditor(user)
addEditors(emailAddresses)
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'
]);
戻る
Grid
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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);
戻る
Image
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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')]);
戻る
List
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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]);
戻る
Multiple
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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);
戻る
Page
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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?');
戻る
Paragraph
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
addRatingItem()
回答者が評価を付けられる新しい質問項目を追加します。
// 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 rating item.
const item = form.addRatingItem();
戻る
Rating
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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');
戻る
Scale
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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');
戻る
Section
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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?');
戻る
Text
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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?');
戻る
Time
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 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);
戻る
Video
- 新しく作成されたアイテム。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
canEditResponse()
フォームに、回答を送信した後に回答を編集するためのリンクを表示するかどうかを指定します。
この設定に関係なく、メソッド Form
を使用すると、フォームの編集権限を持つスクリプト作成者は、レスポンスの編集に使用できる 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()
フォームに対する新しい回答を作成します。質問項目に回答するには、その項目から Item
を作成し、Form
を呼び出してこのフォーム レスポンスに関連付けます。組み立てられたレスポンスを保存するには、Form
を呼び出します。
戻る
Form
- 新しく作成されたフォーム レスポンス。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
deleteAllResponses()
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);
}
パラメータ
名前 | 型 | 説明 |
---|---|---|
index | Integer | フォーム内のすべての項目の中での項目のインデックス。 |
例外
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);
}
パラメータ
名前 | 型 | 説明 |
---|---|---|
item | Item | 削除するアイテム。 |
例外
Error
- フォームに項目が存在しない場合
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
deleteResponse(responseId)
フォームの回答ストアから 1 つの回答を削除します。この方法では、外部レスポンス デスティネーション(スプレッドシートなど)に保存されているレスポンスのコピーは削除されませんが、フォームの概要ビューからレスポンスが削除されます。レスポンス ID は Form
で取得できます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
response | String | 削除するフォームの回答の ID。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 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);
戻る
Destination
- フォームのレスポンス デスティネーションのタイプ。
承認
このメソッドを使用するスクリプトには、次のスコープの 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()
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);
パラメータ
名前 | 型 | 説明 |
---|---|---|
id | Integer | アイテムの 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);
パラメータ
名前 | 型 | 説明 |
---|---|---|
item | Item | 取得するアイテムのタイプ。 |
戻る
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 に基づいて 1 つのフォームの回答を取得します。レスポンス ID は Form
から取得できます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
response | String | フォームの回答の ID。 |
戻る
Form
- フォームの回答。
例外
Error
- レスポンスが存在しない場合
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getResponses()
フォームのすべての回答の配列を取得します。
戻る
Form
- フォームのすべての回答の配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getResponses(timestamp)
指定した日時以降のフォームのすべての回答の配列を取得します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
timestamp | Date | フォームの回答を返すことができる最小の日時。 |
戻る
Form
- フォームの回答のリスト。
承認
このメソッドを使用するスクリプトには、次のスコープの 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 を取得します。set
が 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 回だけ回答できるようにするかどうかを指定します。値が true
の場合、スクリプトはフォームの回答を送信できません。
戻る
Boolean
- フォームで回答者ごとに 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
hasRespondAgainLink()
回答者がフォームの入力を完了した後に、別の回答を送信するためのリンクをフォームに表示するかどうかを決定します。
// 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);
パラメータ
名前 | 型 | 説明 |
---|---|---|
from | Integer | フォーム内のすべての項目の中で、その項目の現在のインデックス。 |
to | Integer | フォーム内のすべての項目の中で、項目の新しいインデックス。 |
戻る
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);
パラメータ
名前 | 型 | 説明 |
---|---|---|
item | Item | 移動するアイテム。 |
to | Integer | フォーム内のすべての項目の中で、項目の新しいインデックス。 |
戻る
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();
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
removeEditor(emailAddress)
指定されたユーザーを Form
の編集者のリストから削除します。この方法では、一般アクセス権を持つユーザー クラスに属するユーザーが Form
にアクセスできないようにはなりません。たとえば、Form
がユーザーのドメイン全体と共有されている場合や、Form
がユーザーがアクセスできる共有ドライブにある場合などです。
ドライブ ファイルの場合、この操作により、ユーザーは閲覧者のリストからも削除されます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
email | String | 削除するユーザーのメールアドレス。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
removeEditor(user)
指定されたユーザーを Form
の編集者のリストから削除します。この方法では、一般アクセス権を持つユーザー クラスに属するユーザーが Form
にアクセスできないようにはなりません。たとえば、Form
がユーザーのドメイン全体と共有されている場合や、Form
がユーザーがアクセスできる共有ドライブにある場合などです。
ドライブ ファイルの場合、この操作により、ユーザーは閲覧者のリストからも削除されます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
user | User | 削除するユーザーを表す。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
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());
パラメータ
名前 | 型 | 説明 |
---|---|---|
enabled | Boolean | フォームで回答を受け付ける場合は true 、受け付けない場合は false です。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setAllowResponseEdits(enabled)
回答を送信した後に回答を編集するためのリンクをフォームに表示するかどうかを設定します。新しいフォームのデフォルトは false
です。
この設定に関係なく、メソッド Form
を使用すると、フォームの編集権限を持つスクリプト作成者は、レスポンスの編集に使用できる 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());
パラメータ
名前 | 型 | 説明 |
---|---|---|
enabled | Boolean | フォームに [回答を編集] リンクを表示する場合は true 、表示しない場合は false です。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 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);
パラメータ
名前 | 型 | 説明 |
---|---|---|
collect | Boolean | フォームでメールアドレスを収集する場合は true 、収集しない場合は false です。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 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);
パラメータ
名前 | 型 | 説明 |
---|---|---|
message | String | フォームの新しい確認メッセージ。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 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);
パラメータ
名前 | 型 | 説明 |
---|---|---|
message | String | フォームで回答を受け付けていない場合に表示するメッセージ。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setDescription(description)
setDestination(type, id)
フォームの回答が保存される宛先を設定します。宛先が明示的に設定されていないフォームを含むすべてのフォームは、フォームの回答ストアに回答のコピーを保存します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
type | Destination | フォームのレスポンス デスティネーションのタイプ。 |
id | String | フォームの応答先の ID。 |
戻る
例外
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());
パラメータ
名前 | 型 | 説明 |
---|---|---|
enabled | Boolean | フォームでクイズ機能を有効にする場合は true 、そうでない場合は false 。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setLimitOneResponsePerUser(enabled)
フォームで回答者ごとに 1 つの回答のみを許可するかどうかを設定します。新しいフォームのデフォルトは false
です。値が true
に設定されている場合、スクリプトはフォームの回答を送信できません。
パラメータ
名前 | 型 | 説明 |
---|---|---|
enabled | Boolean | フォームで回答者ごとに 1 つの回答のみを許可する場合は true 、そうでない場合は false です。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 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());
パラメータ
名前 | 型 | 説明 |
---|---|---|
enabled | Boolean | フォームに進行状況バーが表示される場合は true 、表示されない場合は false 。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setPublishingSummary(enabled)
回答者がフォームを送信した後に、回答の概要を表示するリンクをフォームに表示するかどうかを設定します。新しいフォームのデフォルトは false
です。
パラメータ
名前 | 型 | 説明 |
---|---|---|
enabled | Boolean | true : フォームに [以前の回答を表示] リンクを表示する場合。false : 表示しない場合。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setShowLinkToRespondAgain(enabled)
回答者がフォームの入力を完了した後に、別の回答を送信するためのリンクをフォームに表示するかどうかを設定します。新しいフォームのデフォルトは true
です。
パラメータ
名前 | 型 | 説明 |
---|---|---|
enabled | Boolean | true : フォームに [別の回答を送信] リンクを表示する場合。false : 表示しない場合。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setShuffleQuestions(shuffle)
setTitle(title)
shortenFormUrl(url)
フォームの長い URL を短い URL に変換します。長い URL が Google フォームに属していない場合は、例外をスローします。
パラメータ
名前 | 型 | 説明 |
---|---|---|
url | String | 短縮する 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 の成績を送信します。
コードに on
トリガーが含まれている場合、submit
を呼び出すと on
条件がトリガーされ、無限ループが発生します。無限ループを回避するには、submit
を呼び出す前に、成績がすでに存在するかどうかを確認するコードを追加します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
responses | Form | フォームのすべての回答の配列。 |
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
サポート終了のメソッド
requiresLogin()
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
。
setRequireLogin(requireLogin)
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());
パラメータ
名前 | 型 | 説明 |
---|---|---|
require | Boolean | フォームでユーザーのログインが必要な場合は true 、そうでない場合は false 。 |
戻る
Form
- 現在のフォーム(連結用)。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms