Apps Scriptリファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2025年5月7日水曜日

Google Formsで非公開のフォームを作成したい(setPublished)


手動でフォームを新規作成する場合は非公開で作成されますが

Apps Scriptで setPublished() を書かずにフォームを作ると

公開状態でフォームが作成されるようです

setPublished() の () の中には true か false が入ります
  •  setPublished(true): 公開
  •  setPublished(false): 非公開

以前書いた Google Formsで単一選択の質問を作りたい では setPublished() を指定していないため

作成後に公開済みのURLが取得できています

今回は setPublished(false) にして非公開で作成してみます




Code.gs
function createMultipleChoice() {
const formName = 'Favorite Color Survey';
const description = 'Please tell us your favorite color.';
const title = 'What is your favorite color?';

const form = FormApp.create(formName);
form.setDescription(description);
const item = form.addMultipleChoiceItem();
item.setTitle(title)
.setChoices([
item.createChoice('Red'),
item.createChoice('Blue'),
item.createChoice('Green'),
item.createChoice('Yellow'),
item.createChoice('Other')
])
form.setPublished(false);

Logger.log('Form Edit URL: ' + form.getEditUrl());

}


実行後にForm Edit URLとForm Published URLが出力されます


Form Edit URLを開くと未公開状態のフォーム編集画面が開きます


公開済みの場合は「公開」ボタンの背景色が白くなります


実行後のログにはForm Published URL(公開済みのURL)も出力されますが

非公開なのでアクセスしてもフォームは表示されません


Tips

リファレンスを見ると setPublished は
「公開・非公開」がサポートされているフォームでのみ利用できるようです
This feature is only available for forms that support publishing. 
Use supportsAdvancedResponderPermissions() to check if the form supports publishing.



Reference


setPublished(enabled)

Latest post

Google Formsで記述式の質問に字数制限を設定したい

記述式の質問には「回答の検証」を設定することができます フォームの編集画面 右下の︙メニューで「回答の検証」を選択します 検証方法には「数値」「テキスト」「長さ」「正規表現」という種類があります 今回は字数制限したいので「長さ」を選びます 長さには「最大文字数」か「最小文字数」を...