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で複数の質問と選択肢の順番を毎回シャッフルしたい(Apps Script)

質問や選択肢をシャッフルする方法ついては以下のリンク先に書きました Google Formsで質問の順番をシャッフルしたい(setShuffleQuestions) Google Formsで選択肢の順番を毎回シャッフルしたい(UI設定のみ) Google Formsで選択肢の順...