Class Form

ฟอร์ม

แบบฟอร์มที่มีพร็อพเพอร์ตี้และรายการโดยรวม พร็อพเพอร์ตี้ประกอบด้วยชื่อ การตั้งค่า และตำแหน่งที่จัดเก็บคำตอบ รายการจะรวมถึงรายการคำถาม เช่น ช่องทำเครื่องหมายหรือรายการตัวเลือก ส่วนรายการเลย์เอาต์ จะหมายถึงสิ่งต่างๆ เช่น ตัวแบ่งหน้า คุณเข้าถึงหรือสร้างแบบฟอร์มได้จาก FormApp

// 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());

เมธอด

วิธีการประเภทการแสดงผลรายละเอียดแบบย่อ
addCheckboxGridItem()CheckboxGridItemเพิ่มรายการคำถามใหม่ซึ่งแสดงเป็นตารางกริดของคอลัมน์และแถวที่ช่วยให้ ผู้ตอบเลือกได้หลายตัวเลือกต่อแถวจากลำดับช่องทำเครื่องหมาย
addCheckboxItem()CheckboxItemเพิ่มรายการคำถามใหม่ที่อนุญาตให้ผู้ตอบเลือกช่องทำเครื่องหมายอย่างน้อย 1 ช่อง รวมถึงช่อง "อื่นๆ" ที่ไม่บังคับ
addDateItem()DateItemผนวกรายการคำถามใหม่ที่ช่วยให้ผู้ตอบระบุวันที่ได้
addDateTimeItem()DateTimeItemผนวกรายการคำถามใหม่ที่ช่วยให้ผู้ตอบระบุวันที่และเวลาได้
addDurationItem()DurationItemผนวกรายการคำถามใหม่ที่ช่วยให้ผู้ตอบระบุระยะเวลาได้
addEditor(emailAddress)Formเพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขสำหรับ Form
addEditor(user)Formเพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขสำหรับ Form
addEditors(emailAddresses)Formเพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อเอดิเตอร์สำหรับ Form
addGridItem()GridItemผนวกรายการคำถามใหม่ซึ่งแสดงเป็นตารางกริดของคอลัมน์และแถวที่ช่วยให้ผู้ตอบเลือกได้ 1 ตัวเลือกต่อแถวจากลำดับปุ่มตัวเลือก
addImageItem()ImageItemผนวกรายการเลย์เอาต์ใหม่ที่แสดงรูปภาพ
addListItem()ListItemผนวกรายการคำถามใหม่ที่อนุญาตให้ผู้ตอบเลือกตัวเลือกหนึ่งจากรายการแบบเลื่อนลง
addMultipleChoiceItem()MultipleChoiceItemเพิ่มรายการคำถามใหม่ที่ช่วยให้ผู้ตอบเลือกตัวเลือก 1 รายการจากรายการปุ่มตัวเลือก หรือช่อง "อื่นๆ" ที่ไม่บังคับ
addPageBreakItem()PageBreakItemเพิ่มรายการเลย์เอาต์ใหม่ที่ทำเครื่องหมายจุดเริ่มต้นของหน้า
addParagraphTextItem()ParagraphTextItemเพิ่มรายการคำถามใหม่ที่อนุญาตให้ผู้ตอบป้อนบล็อกข้อความ
addPublishedReader(emailAddress)Formเพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ตอบสำหรับ Form
addPublishedReader(user)Formเพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ตอบสำหรับ Form
addPublishedReaders(emailAddresses)Formเพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้ตอบสำหรับ Form
addRatingItem()RatingItemผนวกรายการคำถามใหม่ที่อนุญาตให้ผู้ตอบให้คะแนน
addScaleItem()ScaleItemเพิ่มรายการคำถามใหม่ที่ช่วยให้ผู้ตอบเลือก 1 ตัวเลือกจากลำดับปุ่มตัวเลือกที่มีหมายเลข
addSectionHeaderItem()SectionHeaderItemเพิ่มรายการเลย์เอาต์ใหม่ที่แสดงภาพเริ่มต้นของส่วน
addTextItem()TextItemเพิ่มรายการคำถามใหม่ที่ช่วยให้ผู้ตอบป้อนข้อความบรรทัดเดียวได้
addTimeItem()TimeItemเพิ่มรายการคำถามใหม่ที่ช่วยให้ผู้ตอบระบุช่วงเวลาของวันได้
addVideoItem()VideoItemเพิ่มรายการเลย์เอาต์ใหม่ที่แสดงวิดีโอ
canEditResponse()Booleanกำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อแก้ไขคำตอบหลังจากส่งหรือไม่
collectsEmail()Booleanกำหนดว่าแบบฟอร์มจะรวบรวมอีเมลของผู้ตอบหรือไม่
createResponse()FormResponseสร้างคำตอบใหม่สำหรับแบบฟอร์ม
deleteAllResponses()Formลบคำตอบที่ส่งทั้งหมดออกจากที่เก็บคำตอบของแบบฟอร์ม
deleteItem(index)voidลบรายการที่ดัชนีที่ระบุจากรายการทั้งหมดในแบบฟอร์ม
deleteItem(item)voidลบรายการที่ระบุ
deleteResponse(responseId)Formลบคำตอบเดียวจากที่เก็บคำตอบของแบบฟอร์ม
getConfirmationMessage()Stringรับข้อความยืนยันของแบบฟอร์ม
getCustomClosedFormMessage()Stringรับข้อความที่กำหนดเองซึ่งจะแสดงหากแบบฟอร์มไม่รับคำตอบ หรือสตริงว่างหากไม่ได้ตั้งค่าข้อความที่กำหนดเอง
getDescription()Stringรับคำอธิบายของแบบฟอร์ม
getDestinationId()Stringรับรหัสของปลายทางการตอบกลับของแบบฟอร์ม
getDestinationType()DestinationTypeรับประเภทของปลายทางคำตอบของแบบฟอร์ม
getEditUrl()Stringรับ URL ที่ใช้เพื่อเข้าถึงโหมดแก้ไขของแบบฟอร์มได้
getEditors()User[]รับรายชื่อเอดิเตอร์สำหรับ Form นี้
getId()Stringรับรหัสของแบบฟอร์ม
getItemById(id)Item|nullรับรายการที่มีรหัสที่ระบุ
getItems()Item[]รับอาร์เรย์ของสินค้าทั้งหมดในแบบฟอร์ม
getItems(itemType)Item[]รับอาร์เรย์ของรายการทั้งหมดของประเภทที่ระบุ
getPublishedReaders()User[]รับรายชื่อผู้ตอบแบบสอบถามสำหรับ Form นี้
getPublishedUrl()Stringรับ URL ที่ใช้ตอบแบบฟอร์มได้
getResponse(responseId)FormResponseรับคำตอบของแบบฟอร์มรายการเดียวตามรหัสคำตอบ
getResponses()FormResponse[]รับอาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์ม
getResponses(timestamp)FormResponse[]รับอาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์มหลังจากวันที่และเวลาที่ระบุ
getShuffleQuestions()Booleanกำหนดว่าจะสุ่มลำดับคำถามในแต่ละหน้าของแบบฟอร์มหรือไม่
getSummaryUrl()Stringรับ URL ที่ใช้ดูสรุปคำตอบของแบบฟอร์มได้
getTitle()Stringรับชื่อของแบบฟอร์ม
hasLimitOneResponsePerUser()Booleanกำหนดว่าแบบฟอร์มอนุญาตให้ผู้ตอบแต่ละคนตอบได้เพียง 1 ครั้งหรือไม่
hasProgressBar()Booleanกำหนดว่าแบบฟอร์มจะแสดงแถบความคืบหน้าหรือไม่
hasRespondAgainLink()Booleanกำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อส่งคำตอบอื่นหลังจากที่ผู้ตอบ กรอกแบบฟอร์มเสร็จหรือไม่
isAcceptingResponses()Booleanกำหนดว่าแบบฟอร์มกำลังรับคำตอบอยู่หรือไม่
isPublished()Booleanกำหนดว่าเผยแพร่แบบฟอร์มหรือไม่
isPublishingSummary()Booleanกำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อดูสรุปคำตอบหลังจากที่ผู้ตอบ กรอกแบบฟอร์มเสร็จหรือไม่
isQuiz()Booleanกำหนดว่าแบบฟอร์มเป็นแบบทดสอบหรือไม่
moveItem(from, to)Itemย้ายรายการที่ดัชนีที่ระบุในรายการทั้งหมดในแบบฟอร์มไปยังดัชนีอื่นที่ระบุ
moveItem(item, toIndex)Itemย้ายรายการที่เลือกไปยังดัชนีที่เลือกในรายการทั้งหมดในแบบฟอร์ม
removeDestination()Formยกเลิกการลิงก์แบบฟอร์มกับปลายทางการตอบกลับปัจจุบัน
removeEditor(emailAddress)Formนำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขสำหรับ Form
removeEditor(user)Formนำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขสำหรับ Form
removePublishedReader(emailAddress)Formนำผู้ใช้ที่ระบุออกจากรายชื่อผู้ตอบสำหรับ Form
removePublishedReader(user)Formนำผู้ใช้ที่ระบุออกจากรายชื่อผู้ตอบสำหรับ Form
setAcceptingResponses(enabled)Formกำหนดว่าแบบฟอร์มยอมรับคำตอบในขณะนี้หรือไม่
setAllowResponseEdits(enabled)Formกำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อแก้ไขคำตอบหลังจากส่งหรือไม่
setCollectEmail(collect)Formกำหนดว่าแบบฟอร์มจะรวบรวมอีเมลของผู้ตอบหรือไม่
setConfirmationMessage(message)Formตั้งค่าข้อความยืนยันของแบบฟอร์ม
setCustomClosedFormMessage(message)Formตั้งค่าข้อความที่จะแสดงหากแบบฟอร์มไม่ยอมรับคำตอบ
setDescription(description)Formตั้งค่าคำอธิบายของแบบฟอร์ม
setDestination(type, id)Formกำหนดปลายทางที่จะบันทึกคำตอบของแบบฟอร์ม
setIsQuiz(enabled)Formตั้งค่าว่าแบบฟอร์มเป็นแบบทดสอบหรือไม่
setLimitOneResponsePerUser(enabled)Formกำหนดว่าแบบฟอร์มอนุญาตให้ผู้ตอบแต่ละคนตอบได้เพียงครั้งเดียวหรือไม่
setProgressBar(enabled)Formตั้งค่าว่าแบบฟอร์มมีแถบความคืบหน้าหรือไม่
setPublished(enabled)Formตั้งค่าว่าแบบฟอร์มเผยแพร่แล้วหรือไม่
setPublishingSummary(enabled)Formกำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อดูสรุปคำตอบหลังจากที่ผู้ตอบส่งแบบฟอร์มหรือไม่
setShowLinkToRespondAgain(enabled)Formกำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อส่งคำตอบอื่นหลังจากที่ผู้ตอบกรอกแบบฟอร์มเสร็จหรือไม่
setShuffleQuestions(shuffle)Formกำหนดว่าจะสุ่มลำดับคำถามในแต่ละหน้าของแบบฟอร์มหรือไม่
setTitle(title)Formตั้งชื่อแบบฟอร์ม
shortenFormUrl(url)Stringแปลง URL แบบยาวของแบบฟอร์มเป็น URL แบบสั้น
submitGrades(responses)Formส่งคะแนนสำหรับ FormResponses ที่ระบุ
supportsAdvancedResponderPermissions()Booleanกำหนดว่าแบบฟอร์มรองรับการเผยแพร่หรือไม่

เอกสารโดยละเอียด

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'
]);

รีเทิร์น

CheckboxGridItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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']);

รีเทิร์น

CheckboxItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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.');

รีเทิร์น

DateItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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);

รีเทิร์น

DateTimeItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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);

รีเทิร์น

DurationItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

addEditor(emailAddress)

เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขสำหรับ Form หากผู้ใช้เคยอยู่ใน รายชื่อผู้ชมหรือผู้ตอบแบบสอบถาม วิธีนี้จะนำผู้ใช้ออกจากรายชื่อ

// 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 editor to the form.
// TODO(developer): replace the emailAddress.
form.addEditor('editor@uni.edu');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressStringอีเมลของผู้ใช้ที่จะเพิ่ม

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

addEditor(user)

เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขสำหรับ Form หากผู้ใช้เคยอยู่ใน รายชื่อผู้ชมหรือผู้ตอบแบบสอบถาม วิธีนี้จะนำผู้ใช้ออกจากรายชื่อ

// Opens the Forms file by its URL.
// TODO(developer): Replace the URL with your own.
const oldForm = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets the editors from the old form.
const users = oldForm.getEditors();

// Creates a new form.
const newForm = FormApp.create('New form');

// Adds the editors to a new form.
users.forEach(user => newForm.addEditor(user));

พารามิเตอร์

ชื่อประเภทคำอธิบาย
userUserการแสดงผู้ใช้ที่จะเพิ่ม

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

addEditors(emailAddresses)

เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อเอดิเตอร์สำหรับ Form หากผู้ใช้ อยู่ในรายชื่อผู้ชมอยู่แล้ว วิธีนี้จะเลื่อนผู้ใช้ดังกล่าวออกจากรายชื่อผู้ชม

// 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 editors to the form.
// TODO(developer): replace the emailAddress.
form.addPublishedReaders(['editor1@uni.edu', 'editor2@uni.edu']);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressesString[]อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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'
]);

รีเทิร์น

GridItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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);

รีเทิร์น

ImageItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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')]);

รีเทิร์น

ListItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

addMultipleChoiceItem()

เพิ่มรายการคำถามใหม่ที่ช่วยให้ผู้ตอบเลือกตัวเลือก 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 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]);

รีเทิร์น

MultipleChoiceItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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);

รีเทิร์น

PageBreakItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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?');

รีเทิร์น

ParagraphTextItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

addPublishedReader(emailAddress)

เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ตอบสำหรับ Form หากผู้ใช้เป็นผู้แก้ไขหรือผู้ดูอยู่แล้ว วิธีนี้จะไม่มีผล

// 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 responder to the form.
// TODO(developer): replace the emailAddress.
form.addPublishedReader('responder@uni.edu');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressStringอีเมลของผู้ใช้ที่จะเพิ่ม

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

addPublishedReader(user)

เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ตอบสำหรับ Form หากผู้ใช้เป็นผู้แก้ไขหรือผู้ดูอยู่แล้ว วิธีนี้จะไม่มีผล

// Opens the Forms file by its URL.
// TODO(developer): Replace the URL with your own.
const oldForm = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets the responders from the old form.
const users = oldForm.getPublishedReaders();

// Creates a new form.
const newForm = FormApp.create('New form');

// Adds the responders to a new form.
users.forEach(user => newForm.addPublishedReader(user));

พารามิเตอร์

ชื่อประเภทคำอธิบาย
userUserการแสดงผู้ใช้ที่จะเพิ่ม

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

addPublishedReaders(emailAddresses)

เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้ตอบสำหรับ Form หากผู้ใช้อยู่ในรายชื่อผู้แก้ไขหรือผู้ดูอยู่แล้ว วิธีนี้จะไม่มีผล

// 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 responders to the form.
// TODO(developer): replace the emailAddress.
form.addPublishedReaders(['responder1@uni.edu', 'responder2@uni.edu']);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressesString[]อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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();

รีเทิร์น

RatingItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

addScaleItem()

เพิ่มรายการคำถามใหม่ที่ช่วยให้ผู้ตอบเลือก 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 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');

รีเทิร์น

ScaleItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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');

รีเทิร์น

SectionHeaderItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

addTextItem()

เพิ่มรายการคำถามใหม่ที่ช่วยให้ผู้ตอบป้อนข้อความบรรทัดเดียวได้

// 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?');

รีเทิร์น

TextItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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?');

รีเทิร์น

TimeItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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);

รีเทิร์น

VideoItem — รายการที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

canEditResponse()

กำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อแก้ไขคำตอบหลังจากส่งหรือไม่

ไม่ว่าการตั้งค่านี้จะเป็นอย่างไร เมธอด FormResponse.getEditResponseUrl() จะอนุญาตให้ผู้เขียนสคริปต์ที่มีสิทธิ์แก้ไขแบบฟอร์มสร้าง 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);

รีเทิร์น

Booleantrue หากแบบฟอร์มแสดงลิงก์ "แก้ไขคำตอบ" 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);

รีเทิร์น

Booleantrue หากแบบฟอร์มรวบรวมอีเมล false หากไม่รวบรวม

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

createResponse()

สร้างคำตอบใหม่สำหรับแบบฟอร์ม หากต้องการตอบคำถาม ให้สร้าง ItemResponse จากรายการ แล้วแนบไปกับคำตอบของแบบฟอร์มนี้โดยเรียกใช้ FormResponse.withItemResponse(response) หากต้องการบันทึกคำตอบที่ประกอบแล้ว ให้เรียกใช้ FormResponse.submit()

รีเทิร์น

FormResponse — คำตอบของแบบฟอร์มที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

deleteAllResponses()

ลบคำตอบที่ส่งทั้งหมดออกจากที่เก็บคำตอบของแบบฟอร์ม วิธีนี้จะไม่ลบสำเนาคำตอบที่จัดเก็บไว้ในปลายทางการตอบกลับภายนอก (เช่น สเปรดชีต) แต่จะล้างมุมมองสรุปของแบบฟอร์ม

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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);
}

พารามิเตอร์

ชื่อประเภทคำอธิบาย
indexIntegerดัชนีของรายการในรายการทั้งหมดในแบบฟอร์ม

ส่ง

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);
}

พารามิเตอร์

ชื่อประเภทคำอธิบาย
itemItemรายการที่จะลบ

ส่ง

Error - หากไม่มีรายการในแบบฟอร์ม

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

deleteResponse(responseId)

ลบคำตอบเดียวจากที่เก็บคำตอบของแบบฟอร์ม วิธีนี้จะไม่ลบสำเนาของคำตอบที่จัดเก็บไว้ในปลายทางคำตอบภายนอก (เช่น สเปรดชีต) แต่จะนำคำตอบออกจากมุมมองสรุปของแบบฟอร์ม คุณสามารถดึงข้อมูลรหัสการตอบกลับได้ด้วย FormResponse.getId()

พารามิเตอร์

ชื่อประเภทคำอธิบาย
responseIdStringรหัสคำตอบของแบบฟอร์มที่จะลบ

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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);

รีเทิร์น

DestinationType — ประเภทของปลายทางการตอบกลับของแบบฟอร์ม

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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()

รับรายชื่อเอดิเตอร์สำหรับ Form นี้

รีเทิร์น

User[] — อาร์เรย์ของผู้ใช้ที่มีสิทธิ์แก้ไข

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
idIntegerรหัสของสินค้า

รีเทิร์น

Item|null — รายการที่มีรหัสที่ระบุ หรือ 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
itemTypeItemTypeประเภทของรายการที่จะดึงข้อมูล

รีเทิร์น

Item[] - อาร์เรย์ของรายการทั้งหมดในประเภทนั้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getPublishedReaders()

รับรายชื่อผู้ตอบแบบสอบถามสำหรับ Form นี้

// 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 responders for the form.
const users = form.getPublishedReaders();
users.forEach(user => console.log(user.getEmail()));

รีเทิร์น

User[] — อาร์เรย์ของผู้ใช้ที่มีสิทธิ์ตอบ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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)

รับคำตอบของแบบฟอร์มรายการเดียวตามรหัสคำตอบ คุณสามารถดึงรหัสคำตอบจาก FormResponse.getId() ได้

พารามิเตอร์

ชื่อประเภทคำอธิบาย
responseIdStringรหัสคำตอบของแบบฟอร์ม

รีเทิร์น

FormResponse — คำตอบของแบบฟอร์ม

ส่ง

Error — หากไม่มีคำตอบ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getResponses()

รับอาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์ม

รีเทิร์น

FormResponse[] — อาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์ม

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getResponses(timestamp)

รับอาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์มหลังจากวันที่และเวลาที่ระบุ

พารามิเตอร์

ชื่อประเภทคำอธิบาย
timestampDateวันที่และเวลาแรกสุดที่ควรแสดงผลการตอบแบบฟอร์ม

รีเทิร์น

FormResponse[] — รายการคำตอบของแบบฟอร์ม

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getShuffleQuestions()

กำหนดว่าจะสุ่มลำดับคำถามในแต่ละหน้าของแบบฟอร์มหรือไม่

รีเทิร์น

Booleantrue หากระบบสุ่มลำดับคำถามในแต่ละหน้าของแบบฟอร์ม false หากไม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

getSummaryUrl()

รับ URL ที่ใช้ดูสรุปคำตอบของแบบฟอร์มได้ เฉพาะผู้ใช้ที่มีสิทธิ์แก้ไขแบบฟอร์มเท่านั้นที่จะเข้าถึง URL ได้ เว้นแต่จะตั้งค่า setPublishingSummary(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.
// 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()

กำหนดว่าแบบฟอร์มอนุญาตให้ผู้ตอบแต่ละคนตอบได้เพียง 1 ครั้งหรือไม่ หากค่าเป็น true สคริปต์จะส่งคำตอบในแบบฟอร์มไม่ได้เลย

รีเทิร์น

Booleantrue หากแบบฟอร์มอนุญาตให้ผู้ตอบแต่ละคนตอบกลับได้ 1 ครั้งเท่านั้น 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());

รีเทิร์น

Booleantrue หากแบบฟอร์มแสดงแถบความคืบหน้า false หากไม่แสดง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

กำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อส่งคำตอบอื่นหลังจากที่ผู้ตอบ กรอกแบบฟอร์มเสร็จหรือไม่

// 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());

รีเทิร์น

Booleantrue หากแบบฟอร์มแสดงลิงก์ "ส่งคำตอบอื่น" 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);

รีเทิร์น

Booleantrue หากแบบฟอร์มยอมรับคำตอบ false หากไม่ยอมรับ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

isPublished()

กำหนดว่าเผยแพร่แบบฟอร์มหรือไม่

ฟีเจอร์นี้ใช้ได้เฉพาะกับแบบฟอร์มที่รองรับการเผยแพร่ ใช้ supportsAdvancedResponderPermissions() เพื่อตรวจสอบว่าแบบฟอร์มรองรับการเผยแพร่หรือไม่

// 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 whether the form is published or not and logs it to the console.
console.log(form.isPublished());

รีเทิร์น

Booleantrue หากเผยแพร่แบบฟอร์มแล้ว false หากยังไม่ได้เผยแพร่

ส่ง

Error — หากเรียกใช้ในแบบฟอร์มที่ไม่รองรับ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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);

รีเทิร์น

Booleantrue หากแบบฟอร์มแสดงลิงก์ "ดูคำตอบก่อนหน้า" 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());

รีเทิร์น

Booleantrue หากแบบฟอร์มยอมรับคำตอบ 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
fromIntegerดัชนีปัจจุบันของรายการในรายการทั้งหมดในแบบฟอร์ม
toIntegerดัชนีใหม่ของรายการในบรรดารายการทั้งหมดในแบบฟอร์ม

รีเทิร์น

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
itemItemรายการที่จะย้าย
toIndexIntegerดัชนีใหม่ของรายการในบรรดารายการทั้งหมดในแบบฟอร์ม

รีเทิร์น

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 — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

removeEditor(emailAddress)

นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขสำหรับ Form วิธีนี้จะไม่บล็อก ผู้ใช้ไม่ให้เข้าถึง Form หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Form กับทั้งโดเมนของผู้ใช้ หรือหาก Form อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้

สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ดังกล่าวออกจากรายชื่อผู้มีสิทธิ์ดูและผู้ตอบด้วย

// Opens the Forms file by its URL.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Removes the editor from the form.
// TODO(developer): replace the emailAddress.
form.removeEditor('editor@uni.edu');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressStringอีเมลของผู้ใช้ที่จะนำออก

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

removeEditor(user)

นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขสำหรับ Form วิธีนี้จะไม่บล็อก ผู้ใช้ไม่ให้เข้าถึง Form หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Form กับทั้งโดเมนของผู้ใช้ หรือหาก Form อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้

สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ดังกล่าวออกจากรายชื่อผู้ดูด้วย

// Opens the Forms file by its URL.
// TODO(developer): Replace the URL with your own.
const form1 = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets the editors from the form.
const users = form1.getEditors();

// Opens another form.
// TODO(developer): Replace the URL with your own.
const form2 = FormApp.openByUrl('https://docs.google.com/forms/d/efg123456/edit');

// Removes editors from the form.
users.forEach(user => form2.removeEditor(user));

พารามิเตอร์

ชื่อประเภทคำอธิบาย
userUserการแสดงผู้ใช้ที่จะนำออก

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

removePublishedReader(emailAddress)

นำผู้ใช้ที่ระบุออกจากรายชื่อผู้ตอบสำหรับ Form วิธีนี้จะไม่ บล็อกไม่ให้ผู้ใช้เข้าถึง Form หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Form กับทั้งโดเมนของผู้ใช้ หรือหาก Form อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้

สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ออกจากรายชื่อผู้ดูและผู้แก้ไขด้วย

// Opens the Forms file by its URL.
// TODO(developer): Replace the URL with your own.
const form = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Removes the responders from the form.
// TODO(developer): replace the emailAddress.
form.removePublishedReader('responder1@uni.edu');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressStringอีเมลของผู้ใช้ที่จะนำออก

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

removePublishedReader(user)

นำผู้ใช้ที่ระบุออกจากรายชื่อผู้ตอบสำหรับ Form วิธีนี้จะไม่ บล็อกไม่ให้ผู้ใช้เข้าถึง Form หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Form กับทั้งโดเมนของผู้ใช้ หรือหาก Form อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้

สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ออกจากรายชื่อผู้ดูและผู้แก้ไขด้วย

// Opens the Forms file by its URL.
// TODO(developer): Replace the URL with your own.
const form1 = FormApp.openByUrl('https://docs.google.com/forms/d/abc123456/edit');

// Gets the responders from the form.
const users = form1.getPublishedReaders();

// Opens another form.
// TODO(developer): Replace the URL with your own.
const form2 = FormApp.openByUrl('https://docs.google.com/forms/d/efg123456/edit');

// Removes responders from the form.
users.forEach(user => form2.removePublishedReader(user));

พารามิเตอร์

ชื่อประเภทคำอธิบาย
userUserการแสดงผู้ใช้ที่จะนำออก

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
enabledBooleantrue หากแบบฟอร์มควรยอมรับคำตอบ false หากไม่ควรยอมรับ

รีเทิร์น

Form — This Form, for chaining.

ส่ง

Error - หากเปิดใช้ในแบบฟอร์มที่ยังไม่ได้เผยแพร่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setAllowResponseEdits(enabled)

กำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อแก้ไขคำตอบหลังจากส่งหรือไม่ ค่าเริ่มต้นสำหรับ แบบฟอร์มใหม่คือ false

ไม่ว่าการตั้งค่านี้จะเป็นอย่างไร เมธอด FormResponse.getEditResponseUrl() จะอนุญาตให้ผู้เขียนสคริปต์ที่มีสิทธิ์แก้ไขแบบฟอร์มสร้าง 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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
enabledBooleantrue หากแบบฟอร์มควรแสดงลิงก์ "แก้ไขคำตอบ" false หากไม่ควรแสดง

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
collectBooleantrue หากแบบฟอร์มควรเก็บรวบรวมอีเมล false หากไม่ควรเก็บรวบรวม อีเมล

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
messageStringข้อความยืนยันใหม่ของแบบฟอร์ม

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
messageStringข้อความที่จะแสดงหากแบบฟอร์มไม่ยอมรับคำตอบ

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setDescription(description)

ตั้งค่าคำอธิบายของแบบฟอร์ม

พารามิเตอร์

ชื่อประเภทคำอธิบาย
descriptionStringคำอธิบายใหม่ของแบบฟอร์ม

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setDestination(type, id)

กำหนดปลายทางที่จะบันทึกคำตอบของแบบฟอร์ม แบบฟอร์มทั้งหมด รวมถึงแบบฟอร์มที่ไม่ได้ ตั้งค่าปลายทางอย่างชัดเจน จะบันทึกสำเนาคำตอบในที่เก็บคำตอบของแบบฟอร์ม

พารามิเตอร์

ชื่อประเภทคำอธิบาย
typeDestinationTypeประเภทของปลายทางคำตอบของแบบฟอร์ม
idStringรหัสของปลายทางคำตอบของแบบฟอร์ม

รีเทิร์น

Form — This Form, for chaining.

ส่ง

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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
enabledBooleantrue หากควรเปิดใช้ฟีเจอร์แบบทดสอบสำหรับแบบฟอร์ม false หากไม่ควรเปิดใช้

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setLimitOneResponsePerUser(enabled)

กำหนดว่าแบบฟอร์มอนุญาตให้ผู้ตอบแต่ละคนตอบได้เพียง 1 ครั้งหรือไม่ ค่าเริ่มต้นสำหรับแบบฟอร์มใหม่คือ false หากตั้งค่าเป็น true สคริปต์จะส่งคำตอบในแบบฟอร์มไม่ได้เลย

พารามิเตอร์

ชื่อประเภทคำอธิบาย
enabledBooleantrue หากแบบฟอร์มควรอนุญาตให้ผู้ตอบแต่ละคนตอบกลับได้ 1 ครั้ง false หากไม่

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
enabledBooleantrue หากแบบฟอร์มแสดงแถบความคืบหน้า false หากไม่แสดง

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setPublished(enabled)

ตั้งค่าว่าแบบฟอร์มเผยแพร่แล้วหรือไม่ ค่าเริ่มต้นสำหรับแบบฟอร์มใหม่คือ true

ฟีเจอร์นี้ใช้ได้เฉพาะกับแบบฟอร์มที่รองรับการเผยแพร่ ใช้ supportsAdvancedResponderPermissions() เพื่อตรวจสอบว่าแบบฟอร์มรองรับการเผยแพร่หรือไม่

คุณต้องเผยแพร่แบบฟอร์มก่อนเพื่อให้ผู้ตอบเข้าถึงได้ เมธอดนี้มีผลแทนการเรียกใช้ setAcceptingResponses(enabled)

// 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',
);

// Publishes the form before sharing it.
form.setPublished(true);

// Checks whether the form is published or not and logs it to the console.
console.log(form.isPublished());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
enabledBooleantrue หากควรเผยแพร่แบบฟอร์ม false หากไม่ควร

รีเทิร์น

Form — This Form, for chaining.

ส่ง

Error — หากเรียกใช้ในแบบฟอร์มที่ไม่รองรับ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setPublishingSummary(enabled)

กำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อดูสรุปคำตอบหลังจากที่ผู้ตอบส่งแบบฟอร์มหรือไม่ ค่าเริ่มต้นสำหรับแบบฟอร์มใหม่คือ false

พารามิเตอร์

ชื่อประเภทคำอธิบาย
enabledBooleantrue หากแบบฟอร์มควรแสดงลิงก์ "ดูคำตอบก่อนหน้า" false หากไม่ควรแสดง

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setShowLinkToRespondAgain(enabled)

กำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อส่งคำตอบอื่นหลังจากที่ผู้ตอบกรอกแบบฟอร์มเสร็จหรือไม่ ค่าเริ่มต้นสำหรับแบบฟอร์มใหม่คือ true

พารามิเตอร์

ชื่อประเภทคำอธิบาย
enabledBooleantrue หากแบบฟอร์มควรแสดงลิงก์ "ส่งคำตอบอื่น" false หากไม่ควรแสดง

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setShuffleQuestions(shuffle)

กำหนดว่าจะสุ่มลำดับคำถามในแต่ละหน้าของแบบฟอร์มหรือไม่

พารามิเตอร์

ชื่อประเภทคำอธิบาย
shuffleBooleantrue หากควรสุ่มลำดับคำถามในแต่ละหน้าของแบบฟอร์ม false หากไม่ควร

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

setTitle(title)

ตั้งชื่อแบบฟอร์ม

พารามิเตอร์

ชื่อประเภทคำอธิบาย
titleStringชื่อใหม่ของแบบฟอร์ม

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

shortenFormUrl(url)

แปลง URL แบบยาวของแบบฟอร์มเป็น URL แบบสั้น ส่งข้อยกเว้นหาก URL แบบยาวไม่ได้ เป็นของ Google ฟอร์ม

พารามิเตอร์

ชื่อประเภทคำอธิบาย
urlStringURL ที่จะย่อ

รีเทิร์น

String — URL ในรูปแบบ http://goo.gl/forms/1234

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

submitGrades(responses)

ส่งคะแนนสำหรับ FormResponses ที่ระบุ

หากโค้ดมีทริกเกอร์ onFormSubmit การเรียก submitGrades() จะทริกเกอร์เงื่อนไข onFormSubmit และทำให้เกิดลูปที่ไม่มีที่สิ้นสุด หากต้องการป้องกันไม่ให้เกิดลูปไม่สิ้นสุด ให้เพิ่มโค้ดที่ตรวจสอบว่ามีคะแนนอยู่แล้วหรือไม่ก่อนเรียกใช้ submitGrades()

พารามิเตอร์

ชื่อประเภทคำอธิบาย
responsesFormResponse[]อาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์ม

รีเทิร์น

Form — This Form, for chaining.

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

supportsAdvancedResponderPermissions()

กำหนดว่าแบบฟอร์มรองรับการเผยแพร่หรือไม่ วิธีนี้ใช้เพื่อพิจารณาว่ามีเมธอด setPublished(enabled) และ isPublished() รวมถึงสิทธิ์ของผู้ตอบ หรือไม่

// 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 whether the form supports publishing or not and logs it to the
// console.
console.log(form.supportsAdvancedResponderPermissions());

รีเทิร์น

Booleantrue หากแบบฟอร์มรองรับการเผยแพร่ false หากไม่รองรับ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms

วิธีการที่เลิกใช้งานแล้ว