全体的なプロパティとアイテムを含むフォーム。プロパティには、タイトル、設定、レスポンスの保存場所が含まれます。項目にはチェックボックスやラジオボタンなどの質問項目が含まれ、レイアウト項目は改ページなどを指します。フォームには 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 行につき 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 件の回答のみを許可するかどうかを指定します。 |
hasProgressBar() | Boolean | フォームに進行状況バーを表示するかどうかを指定します。 |
hasRespondAgainLink() | Boolean | 回答者がフォームに入力した後に、別の回答を送信するリンクがフォームに表示されるかどうかを指定します。 |
isAcceptingResponses() | Boolean | フォームが現在回答を受け付けているかどうかを確認できます。 |
isPublishingSummary() | Boolean | 回答者がフォームへの入力後に回答の概要を表示するリンクをフォームに表示するかどうかを指定します。 |
isQuiz() | Boolean | フォームがテストかどうかを判断します。 |
moveItem(from, to) | Item | フォーム内のすべてのアイテム間で、指定されたインデックスのアイテムを別のインデックスに移動します。 |
moveItem(item, toIndex) | Item | フォーム内のすべてのアイテムのうち、特定のアイテムを特定のインデックスに移動します。 |
removeDestination() | Form | フォームと現在の回答先とのリンクを解除します。 |
removeEditor(emailAddress) | Form | Form の編集者のリストから指定されたユーザーを削除します。 |
removeEditor(user) | Form | Form の編集者のリストから指定されたユーザーを削除します。 |
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 | 指定された FormResponses の成績を送信します。 |
詳細なドキュメント
addCheckboxGridItem()
列と行のグリッドとして表示される新しい質問項目を追加し、回答者が一連のチェックボックスから 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 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)
addEditor(user)
addEditors(emailAddresses)
addGridItem()
新しい質問項目が列と行のグリッドとして表示されるため、回答者は一連のラジオボタンから 1 つの行を 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 を生成して、その 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()
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 は FormResponse.getId()
で取得できます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
responseId | 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);
復路
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()
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);
パラメータ
名前 | 型 | 説明 |
---|---|---|
itemType | ItemType | 取得するアイテムのタイプ。 |
復路
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()
から取得できます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
responseId | String | フォーム レスポンスの 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)
指定した日時以降のフォームの回答配列をすべて取得します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
timestamp | Date | フォームの回答を最も早く返す日時。 |
復路
FormResponse[]
- フォームの回答のリスト。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getShuffleQuestions()
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()
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 | 移動するアイテム。 |
toIndex | 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
へのアクセスをブロックしません。
ドライブ内のファイルの場合、閲覧者のリストからユーザーが削除されます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
emailAddress | 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
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());
パラメータ
名前 | 型 | 説明 |
---|---|---|
enabled | Boolean | true フォームで回答を受け付けるべき場合。false そうでない場合。 |
復路
承認
この方法を使用するスクリプトには、次の 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());
パラメータ
名前 | 型 | 説明 |
---|---|---|
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 | DestinationType | フォームの回答先の種類。 |
id | String | フォームの回答先 ID。 |
復路
例外
Error
- 指定されたデスティネーション ID が無効の場合
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setIsQuiz(enabled)
フォームがテストかどうかを設定します。新しいフォームのデフォルトは false
です。
採点式の質問はテストでのみ許可されています。これを false
に設定すると、すべての質問から採点オプションがすべて削除されます。
テストの設定は新しい Google フォームの管理画面でのみ使用できます。フォームでテストを作成すると、フォームで新しい 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)
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)
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());
パラメータ
名前 | 型 | 説明 |
---|---|---|
requireLogin | Boolean | フォームへのログインをユーザーに要求する場合は true 、そうでない場合は false 。 |
復路
Form
- 現在のフォーム(チェーン用)。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setShowLinkToRespondAgain(enabled)
setShuffleQuestions(shuffle)
setTitle(title)
shortenFormUrl(url)
submitGrades(responses)
指定された FormResponses の成績を送信します。
コードに onFormSubmit
トリガーが含まれている場合、submitGrades()
を呼び出すと onFormSubmit
条件がトリガーされ、無限ループが発生します。無限ループを回避するには、submitGrades()
を呼び出す前に、成績がすでに存在するかどうかを確認するコードを追加します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
responses | FormResponse[] | フォームの回答の配列。 |
復路
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms