- 是否接受回應
- 表單關閉時文字訊息,Google Forms 畫面上是這樣描述:若表單不再接受回覆,作答者就會看到這則訊息
- 指定日期:建立 GAS 觸發器
- 達到指定回覆數之後:使用 onFormSubmit 處理
我是選擇手動去 Google Forms 上設定就好,沒有一定要 GAS 處理到位,但我沒有常常製作 Google Forms 需求就是
該筆記重點放在「表單關閉時文字訊息」設定上,因為官方文件上範例-setCustomClosedFormMessage(message) 無法正常設定
該筆記重點放在「表單關閉時文字訊息」設定上,因為官方文件上範例-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);
修正後語法
const form = FormApp.openByUrl('https://docs.google.com/forms/d/1aLQnrVyq8WZkUrczW3oUt_Xg4xnjd6xLy3ALmu-sNIk/edit',);
const isAccepting = form.isAcceptingResponses();
try {
if (!isAccepting) {
form.setAcceptingResponses(true);
}
form.setCustomClosedFormMessage('The form is no longer accepting responses.');
form.setAcceptingResponses(false);
} finally {
form.setAcceptingResponses(isAccepting);
}
const message = form.getCustomClosedFormMessage();
console.log(message);
setCustomClosedFormMessage() 必須在 Forms 是接受回應狀態下才可以進行設定,一旦表單關閉,就無法設定表單關閉時文字訊息

沒有留言:
張貼留言