แบบฟอร์มที่มีพร็อพเพอร์ตี้และรายการโดยรวม พร็อพเพอร์ตี้ ได้แก่ ชื่อ การตั้งค่า และตำแหน่งที่จัดเก็บคําตอบ รายการต่างๆ ประกอบด้วยรายการคำถาม เช่น ช่องทำเครื่องหมายหรือรายการตัวเลือก ส่วนรายการเลย์เอาต์หมายถึงสิ่งต่างๆ เช่น การแบ่งหน้า คุณเข้าถึงหรือสร้างแบบฟอร์มได้จาก Form
// Open a form by ID and create a new spreadsheet.
const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
const 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());
เมธอด
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
---|---|---|
add | Checkbox | ต่อท้ายรายการคำถามใหม่ซึ่งแสดงเป็นตารางกริดของคอลัมน์และแถว ซึ่งช่วยให้ผู้ตอบเลือกตัวเลือกหลายรายการต่อแถวจากช่องทำเครื่องหมายตามลำดับได้ |
add | Checkbox | ต่อท้ายรายการคำถามใหม่ซึ่งอนุญาตให้ผู้ตอบเลือกช่องทำเครื่องหมายอย่างน้อย 1 ช่อง รวมถึงช่อง "อื่นๆ" (ไม่บังคับ) |
add | Date | ต่อท้ายรายการคำถามใหม่ซึ่งอนุญาตให้ผู้ตอบระบุวันที่ |
add | Date | ต่อท้ายรายการคำถามใหม่ซึ่งช่วยให้ผู้ตอบระบุวันที่และเวลาได้ |
add | Duration | ต่อท้ายรายการคําถามใหม่ซึ่งช่วยให้ผู้ตอบระบุระยะเวลาได้ |
add | Form | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขของ Form |
add | Form | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขของ Form |
add | Form | เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขของ Form |
add | Grid | ต่อท้ายรายการคำถามใหม่ซึ่งแสดงเป็นตารางกริดของคอลัมน์และแถว ซึ่งช่วยให้ผู้ตอบเลือกตัวเลือกได้ 1 รายการต่อแถวจากปุ่มตัวเลือกตามลำดับ |
add | Image | ต่อท้ายรายการเลย์เอาต์ใหม่ที่แสดงรูปภาพ |
add | List | ต่อท้ายรายการคําถามใหม่ซึ่งอนุญาตให้ผู้ตอบเลือกตัวเลือกเดียวจากรายการแบบเลื่อนลง |
add | Multiple | เพิ่มรายการคำถามใหม่ที่ให้ผู้ตอบเลือกตัวเลือกเดียวจากรายการปุ่มตัวเลือก หรือช่อง "อื่นๆ" (ไม่บังคับ) |
add | Page | เพิ่มรายการเลย์เอาต์ใหม่ที่ทําเครื่องหมายจุดเริ่มต้นของหน้า |
add | Paragraph | เพิ่มรายการคำถามใหม่ที่ให้ผู้ตอบป้อนบล็อกข้อความ |
add | Rating | ต่อท้ายรายการคำถามใหม่ซึ่งอนุญาตให้ผู้ตอบให้คะแนน |
add | Scale | ต่อท้ายรายการคำถามใหม่ซึ่งอนุญาตให้ผู้ตอบเลือกตัวเลือกเดียวจากปุ่มตัวเลือกตามลำดับที่เรียงลำดับไว้ |
add | Section | ต่อท้ายรายการเลย์เอาต์ใหม่ซึ่งระบุจุดเริ่มต้นของส่วน |
add | Text | ต่อท้ายรายการคำถามใหม่ซึ่งอนุญาตให้ผู้ตอบป้อนข้อความได้ 1 บรรทัด |
add | Time | ต่อท้ายรายการคําถามใหม่ซึ่งช่วยให้ผู้ตอบระบุเวลาของวันได้ |
add | Video | ต่อท้ายรายการเลย์เอาต์ใหม่ที่แสดงวิดีโอ |
can | Boolean | กำหนดว่าแบบฟอร์มจะแสดงลิงก์สำหรับแก้ไขคำตอบหลังจากส่งหรือไม่ |
collects | Boolean | กำหนดว่าแบบฟอร์มจะรวบรวมอีเมลของผู้ตอบหรือไม่ |
create | Form | สร้างคำตอบใหม่ในแบบฟอร์ม |
delete | Form | ลบคำตอบที่ส่งทั้งหมดออกจากที่เก็บคำตอบของแบบฟอร์ม |
delete | void | ลบรายการที่อยู่ที่ดัชนีที่ระบุจากรายการทั้งหมดในแบบฟอร์ม |
delete | void | ลบรายการที่ระบุ |
delete | Form | ลบคำตอบรายการเดียวออกจากที่เก็บคำตอบของแบบฟอร์ม |
get | String | รับข้อความยืนยันของแบบฟอร์ม |
get | String | รับข้อความที่กําหนดเองซึ่งจะแสดงขึ้นหากแบบฟอร์มไม่ยอมรับคําตอบ หรือสตริงว่างหากไม่ได้ตั้งค่าข้อความที่กําหนดเอง |
get | String | รับคําอธิบายของแบบฟอร์ม |
get | String | รับรหัสของปลายทางการตอบกลับของแบบฟอร์ม |
get | Destination | รับประเภทของปลายทางการตอบกลับของแบบฟอร์ม |
get | String | รับ URL ที่สามารถใช้เข้าถึงโหมดแก้ไขของแบบฟอร์ม |
get | User[] | รับรายชื่อผู้แก้ไขสำหรับ Form นี้ |
get | String | รับรหัสของแบบฟอร์ม |
get | Item | รับรายการที่มีรหัสที่ระบุ |
get | Item[] | รับอาร์เรย์ของรายการทั้งหมดในแบบฟอร์ม |
get | Item[] | รับอาร์เรย์ของรายการทั้งหมดในประเภทที่ระบุ |
get | String | รับ URL ที่สามารถใช้ตอบแบบฟอร์ม |
get | Form | รับคําตอบของแบบฟอร์มรายการเดียวตามรหัสคําตอบ |
get | Form | รับอาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์ม |
get | Form | รับอาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์มหลังจากวันที่และเวลาที่กำหนด |
get | Boolean | กำหนดว่าจะสุ่มลำดับคำถามในแต่ละหน้าของแบบฟอร์มหรือไม่ |
get | String | รับ URL ที่สามารถใช้เพื่อดูสรุปคำตอบของแบบฟอร์ม |
get | String | รับชื่อของแบบฟอร์ม |
has | Boolean | กำหนดว่าแบบฟอร์มอนุญาตให้ผู้ตอบตอบได้เพียงครั้งเดียวหรือไม่ |
has | Boolean | กำหนดว่าแบบฟอร์มจะแสดงแถบความคืบหน้าหรือไม่ |
has | Boolean | กำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อส่งคำตอบอื่นหรือไม่หลังจากที่ผู้ตอบกรอกแบบฟอร์มเสร็จแล้ว |
is | Boolean | ระบุว่าขณะนี้แบบฟอร์มรับคำตอบอยู่หรือไม่ |
is | Boolean | กำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อดูสรุปคำตอบหลังจากที่ผู้ตอบกรอกแบบฟอร์มเสร็จหรือไม่ |
is | Boolean | ระบุว่าแบบฟอร์มเป็นแบบทดสอบหรือไม่ |
move | Item | ย้ายรายการที่ดัชนีหนึ่งๆ ของรายการทั้งหมดในแบบฟอร์มไปยังดัชนีอื่นที่ระบุ |
move | Item | ย้ายรายการหนึ่งๆ ไปยังดัชนีหนึ่งๆ ของรายการทั้งหมดในแบบฟอร์ม |
remove | Form | ยกเลิกการลิงก์แบบฟอร์มจากปลายทางการตอบกลับปัจจุบัน |
remove | Form | นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขของ Form |
remove | Form | นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขของ Form |
set | Form | ตั้งค่าว่าขณะนี้แบบฟอร์มรับคำตอบหรือไม่ |
set | Form | ตั้งค่าว่าแบบฟอร์มจะแสดงลิงก์สำหรับแก้ไขคำตอบหลังจากส่งหรือไม่ |
set | Form | ตั้งค่าว่าแบบฟอร์มจะรวบรวมอีเมลของผู้ตอบหรือไม่ |
set | Form | ตั้งค่าข้อความยืนยันของแบบฟอร์ม |
set | Form | ตั้งค่าข้อความที่จะแสดงหากแบบฟอร์มไม่ยอมรับคำตอบ |
set | Form | ตั้งค่าคําอธิบายของแบบฟอร์ม |
set | Form | กำหนดปลายทางที่จะบันทึกคำตอบของแบบฟอร์ม |
set | Form | ตั้งค่าว่าแบบฟอร์มเป็นแบบทดสอบหรือไม่ |
set | Form | ตั้งค่าว่าแบบฟอร์มจะอนุญาตให้ผู้ตอบตอบได้เพียงครั้งเดียวหรือไม่ |
set | Form | ตั้งค่าว่าแบบฟอร์มจะมีแถบความคืบหน้าหรือไม่ |
set | Form | ตั้งค่าว่าแบบฟอร์มจะแสดงลิงก์เพื่อดูสรุปคำตอบหลังจากที่ผู้ตอบส่งแบบฟอร์มหรือไม่ |
set | Form | ตั้งค่าว่าแบบฟอร์มจะแสดงลิงก์เพื่อส่งคำตอบอื่นหรือไม่หลังจากที่ผู้ตอบกรอกแบบฟอร์มเสร็จแล้ว |
set | Form | ตั้งค่าว่าจะสุ่มลําดับคําถามในแต่ละหน้าของแบบฟอร์มหรือไม่ |
set | Form | ตั้งค่าชื่อของแบบฟอร์ม |
shorten | String | แปลง URL แบบยาวของแบบฟอร์มเป็น URL แบบสั้น |
submit | Form | ส่งคะแนนสำหรับ FormResponses ที่ระบุ |
วิธีการที่เลิกใช้งาน
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
---|---|---|
| Boolean | กำหนดว่าแบบฟอร์มกำหนดให้ผู้ตอบต้องเข้าสู่ระบบบัญชีในโดเมนหรือโดเมนย่อยเดียวกันก่อนตอบหรือไม่ |
| Form | ตั้งค่าว่าแบบฟอร์มกำหนดให้ผู้ตอบต้องเข้าสู่ระบบบัญชีในโดเมนเดียวกันหรือโดเมนย่อยก่อนตอบหรือไม่ |
เอกสารประกอบโดยละเอียด
addCheckboxGridItem()
ต่อท้ายรายการคำถามใหม่ซึ่งแสดงเป็นตารางกริดของคอลัมน์และแถว ซึ่งช่วยให้ผู้ตอบเลือกตัวเลือกหลายรายการต่อแถวจากช่องทำเครื่องหมายตามลำดับได้
// 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();
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'
]);
รีเทิร์น
Checkbox
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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']);
รีเทิร์น
Checkbox
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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.');
รีเทิร์น
Date
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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);
รีเทิร์น
Date
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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);
รีเทิร์น
Duration
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
addEditor(emailAddress)
เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขของ Form
หากผู้ใช้อยู่ในรายการผู้ชมอยู่แล้ว วิธีการนี้จะเลื่อนผู้ใช้ออกจากรายการผู้ชม
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
email | String | อีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
addEditor(user)
เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขของ Form
หากผู้ใช้อยู่ในรายการผู้ชมอยู่แล้ว วิธีการนี้จะเลื่อนผู้ใช้ออกจากรายการผู้ชม
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
addEditors(emailAddresses)
เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขของ Form
หากผู้ใช้รายใดอยู่ในรายชื่อผู้ชมอยู่แล้ว วิธีการนี้จะเลื่อนผู้ใช้รายนั้นออกจากรายชื่อผู้ชม
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
email | String[] | อาร์เรย์อีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
addGridItem()
ต่อท้ายรายการคำถามใหม่ซึ่งแสดงเป็นตารางกริดของคอลัมน์และแถว ซึ่งช่วยให้ผู้ตอบเลือกตัวเลือกได้ 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'
]);
รีเทิร์น
Grid
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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);
รีเทิร์น
Image
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
addListItem()
ต่อท้ายรายการคําถามใหม่ซึ่งอนุญาตให้ผู้ตอบเลือกตัวเลือกเดียวจากรายการแบบเลื่อนลง
// 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')]);
รีเทิร์น
List
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
addMultipleChoiceItem()
เพิ่มรายการคำถามใหม่ที่ให้ผู้ตอบเลือกตัวเลือกเดียวจากรายการปุ่มตัวเลือก หรือช่อง "อื่นๆ" (ไม่บังคับ)
// 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]);
รีเทิร์น
Multiple
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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);
รีเทิร์น
Page
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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?');
รีเทิร์น
Paragraph
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
addRatingItem()
ต่อท้ายรายการคำถามใหม่ซึ่งอนุญาตให้ผู้ตอบให้คะแนน
// 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 rating item.
const item = form.addRatingItem();
รีเทิร์น
Rating
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
addScaleItem()
ต่อท้ายรายการคำถามใหม่ซึ่งอนุญาตให้ผู้ตอบเลือกตัวเลือกเดียวจากปุ่มตัวเลือกตามลำดับที่เรียงลำดับไว้
// 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');
รีเทิร์น
Scale
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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');
รีเทิร์น
Section
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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?');
รีเทิร์น
Text
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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?');
รีเทิร์น
Time
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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);
รีเทิร์น
Video
— รายการที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
canEditResponse()
กำหนดว่าแบบฟอร์มจะแสดงลิงก์สำหรับแก้ไขคำตอบหลังจากส่งหรือไม่
การตั้งค่านี้ไม่ส่งผลต่อเมธอด Form
ซึ่งอนุญาตให้ผู้เขียนสคริปต์ที่มีสิทธิ์แก้ไขแบบฟอร์มสร้าง 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()
สร้างคำตอบใหม่ในแบบฟอร์ม หากต้องการตอบรายการคำถาม ให้สร้าง Item
จากรายการ แล้วแนบไปกับคำตอบแบบฟอร์มนี้โดยเรียกใช้ Form
หากต้องการบันทึกคำตอบที่ประกอบแล้ว ให้โทรหา Form
รีเทิร์น
Form
— คำตอบแบบฟอร์มที่สร้างขึ้นใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
deleteAllResponses()
ลบคำตอบที่ส่งทั้งหมดออกจากที่เก็บคำตอบของแบบฟอร์ม วิธีนี้จะไม่ลบสำเนาคำตอบที่จัดเก็บไว้ในปลายทางคำตอบภายนอก (เช่น สเปรดชีต) แต่จะล้างมุมมองข้อมูลสรุปของแบบฟอร์ม
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
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)
ลบคำตอบรายการเดียวออกจากที่เก็บคำตอบของแบบฟอร์ม วิธีนี้จะไม่ลบสำเนาคำตอบที่จัดเก็บไว้ในปลายทางคำตอบภายนอก (เช่น สเปรดชีต) แต่จะนําคำตอบออกจากมุมมองข้อมูลสรุปของแบบฟอร์ม คุณเรียกดูรหัสคำตอบได้ด้วย Form
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
response | String | รหัสของคำตอบในแบบฟอร์มที่จะลบ |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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()
รับรหัสของปลายทางการตอบกลับของแบบฟอร์ม
// 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
— รหัสของปลายทางคำตอบของแบบฟอร์ม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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);
รีเทิร์น
Destination
— ประเภทของปลายทางการตอบกลับของแบบฟอร์ม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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()
รับรหัสของแบบฟอร์ม
// 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
— รหัสของแบบฟอร์ม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getItemById(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 | รหัสของสินค้า |
รีเทิร์น
Item
— รายการที่มีรหัสที่ระบุ หรือ 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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
item | Item | ประเภทของรายการที่จะดึงข้อมูล |
รีเทิร์น
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)
รับคําตอบของแบบฟอร์มรายการเดียวตามรหัสคําตอบ คุณเรียกดูรหัสคำตอบได้จาก Form
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
response | String | รหัสสําหรับคําตอบแบบฟอร์ม |
รีเทิร์น
Form
— คำตอบในแบบฟอร์ม
โยน
Error
— หากไม่มีคำตอบ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getResponses()
รับอาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์ม
รีเทิร์น
Form
— อาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์ม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getResponses(timestamp)
รับอาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์มหลังจากวันที่และเวลาที่กำหนด
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
timestamp | Date | วันที่และเวลาแรกสุดที่ควรแสดงคําตอบของแบบฟอร์ม |
รีเทิร์น
Form
— รายการคำตอบในแบบฟอร์ม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getShuffleQuestions()
กำหนดว่าจะสุ่มลำดับคำถามในแต่ละหน้าของแบบฟอร์มหรือไม่
รีเทิร์น
Boolean
— true
หากมีการจัดเรียงคำถามในแต่ละหน้าของแบบฟอร์มแบบสุ่ม
false
หากไม่มี
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getSummaryUrl()
รับ URL ที่สามารถใช้เพื่อดูสรุปคำตอบของแบบฟอร์ม เว้นแต่ว่า set
จะตั้งค่าเป็น 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()
กำหนดว่าแบบฟอร์มอนุญาตให้ผู้ตอบตอบได้เพียงครั้งเดียวหรือไม่ หากค่าคือ true
สคริปต์จะส่งคําตอบในแบบฟอร์มไม่ได้เลย
รีเทิร์น
Boolean
— true
หากแบบฟอร์มอนุญาตให้ผู้ตอบตอบได้เพียงครั้งเดียว และ false
หากไม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
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 | รายการที่จะย้าย |
to | 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();
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
removeEditor(emailAddress)
นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขของ Form
วิธีการนี้จะไม่บล็อกไม่ให้ผู้ใช้เข้าถึงForm
หากผู้ใช้อยู่ในกลุ่มที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากForm
มีการแชร์กับโดเมนทั้งหมดของผู้ใช้ หรือหากForm
อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้
สำหรับไฟล์ในไดรฟ์ ระบบจะนำผู้ใช้ออกจากรายชื่อผู้ดูด้วย
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
email | String | อีเมลของผู้ใช้ที่จะนำออก |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
removeEditor(user)
นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขของ Form
วิธีการนี้จะไม่บล็อกไม่ให้ผู้ใช้เข้าถึงForm
หากผู้ใช้อยู่ในกลุ่มที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากForm
มีการแชร์กับโดเมนทั้งหมดของผู้ใช้ หรือหากForm
อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้
สำหรับไฟล์ในไดรฟ์ ระบบจะนำผู้ใช้ออกจากรายชื่อผู้ดูด้วย
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะนำออก |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
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 หากไม่ควรยอมรับ |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setAllowResponseEdits(enabled)
ตั้งค่าว่าแบบฟอร์มจะแสดงลิงก์สำหรับแก้ไขคำตอบหลังจากส่งหรือไม่ ค่าเริ่มต้นสำหรับแบบฟอร์มใหม่คือ false
การตั้งค่านี้ไม่ส่งผลต่อเมธอด Form
ซึ่งอนุญาตให้ผู้เขียนสคริปต์ที่มีสิทธิ์แก้ไขแบบฟอร์มสร้าง 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 หากไม่ |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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 หากไม่รวบรวม |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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 | ข้อความยืนยันใหม่ของแบบฟอร์ม |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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 | ข้อความที่จะแสดงหากแบบฟอร์มไม่ยอมรับคำตอบ |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setDescription(description)
ตั้งค่าคําอธิบายของแบบฟอร์ม
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
description | String | คำอธิบายใหม่ของแบบฟอร์ม |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setDestination(type, id)
กำหนดปลายทางที่จะบันทึกคำตอบของแบบฟอร์ม แบบฟอร์มทั้งหมด รวมถึงแบบฟอร์มที่ไม่ได้ตั้งค่าปลายทางไว้อย่างชัดเจนจะบันทึกสําเนาคําตอบไว้ในที่เก็บคําตอบของแบบฟอร์ม
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
type | Destination | ประเภทของปลายทางการตอบกลับของแบบฟอร์ม |
id | String | รหัสของปลายทางการตอบกลับของแบบฟอร์ม |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
โยน
Error
— หากรหัสปลายทางที่ระบุไม่ถูกต้อง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setIsQuiz(enabled)
ตั้งค่าว่าแบบฟอร์มเป็นแบบทดสอบหรือไม่ ค่าเริ่มต้นสำหรับแบบฟอร์มใหม่คือ false
ระบบอนุญาตให้ใช้คำถามแบบให้คะแนนในแบบทดสอบเท่านั้น ดังนั้นการตั้งค่านี้เป็น false
จะนําตัวเลือกการให้คะแนนทั้งหมดออกจากคําถามทั้งหมด
การตั้งค่าแบบทดสอบจะใช้ได้ใน UI ใหม่ของฟอร์มเท่านั้น การทำแบบฟอร์มเป็นแบบทดสอบจะเป็นการเลือกใช้ 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 หากไม่ควร |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setLimitOneResponsePerUser(enabled)
ตั้งค่าว่าแบบฟอร์มจะอนุญาตให้ผู้ตอบตอบได้เพียงครั้งเดียวหรือไม่ ค่าเริ่มต้นสำหรับแบบฟอร์มใหม่คือ false
หากตั้งค่าเป็น true
สคริปต์จะส่งคำตอบในแบบฟอร์มไม่ได้เลย
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
enabled | Boolean | true หากแบบฟอร์มควรอนุญาตให้ผู้ตอบตอบได้เพียงครั้งเดียว false หากไม่ |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
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 หากไม่แสดง |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setPublishingSummary(enabled)
ตั้งค่าว่าแบบฟอร์มจะแสดงลิงก์เพื่อดูสรุปคำตอบหลังจากที่ผู้ตอบส่งแบบฟอร์มหรือไม่ ค่าเริ่มต้นสำหรับแบบฟอร์มใหม่คือ false
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
enabled | Boolean | true หากต้องการให้แบบฟอร์มแสดงลิงก์ "ดูคำตอบก่อนหน้า" false หากไม่ |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setShowLinkToRespondAgain(enabled)
ตั้งค่าว่าแบบฟอร์มจะแสดงลิงก์เพื่อส่งคำตอบอื่นหรือไม่หลังจากที่ผู้ตอบกรอกแบบฟอร์มเสร็จแล้ว ค่าเริ่มต้นสำหรับแบบฟอร์มใหม่คือ true
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
enabled | Boolean | true หากแบบฟอร์มควรแสดงลิงก์ "ส่งคำตอบอื่น" false หากไม่ |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setShuffleQuestions(shuffle)
ตั้งค่าว่าจะสุ่มลําดับคําถามในแต่ละหน้าของแบบฟอร์มหรือไม่
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
shuffle | Boolean | true หากควรสุ่มลําดับคําถามในแต่ละหน้าของแบบฟอร์ม false หากไม่ควร |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setTitle(title)
ตั้งค่าชื่อของแบบฟอร์ม
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
title | String | ชื่อใหม่ของแบบฟอร์ม |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
shortenFormUrl(url)
แปลง URL แบบยาวของแบบฟอร์มเป็น URL แบบสั้น แสดงข้อยกเว้นหาก URL แบบยาวไม่ได้เป็นของ Google ฟอร์ม
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
url | String | URL ที่จะย่อ |
รีเทิร์น
String
— URL ในรูปแบบ http://goo.gl/forms/1234
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
submitGrades(responses)
ส่งคะแนนสำหรับ FormResponses ที่ระบุ
หากโค้ดของคุณมีทริกเกอร์ on
การเรียก submit
จะทริกเกอร์เงื่อนไข on
และทำให้เกิดลูปที่ไม่มีที่สิ้นสุด เพื่อป้องกันไม่ให้เกิดการวนซ้ำไปเรื่อยๆ ให้เพิ่มโค้ดที่ตรวจสอบว่ามีคะแนนอยู่แล้วหรือไม่ก่อนที่จะเรียกใช้ submit
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
responses | Form | อาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์ม |
รีเทิร์น
Form
— Form
นี้สําหรับการต่อเชื่อม
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
วิธีการที่เลิกใช้งาน
requiresLogin()
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
หากไม่ได้กำหนด
setRequireLogin(requireLogin)
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());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
require | Boolean | true หากแบบฟอร์มกำหนดให้ผู้ใช้เข้าสู่ระบบ false หากไม่ได้กำหนด |
รีเทิร์น
Form
— รูปแบบปัจจุบัน (สําหรับการต่อเชื่อม)
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms