手動でフォームを新規作成する場合は非公開で作成されますが
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 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)