Class Form

แบบฟอร์ม

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

// Open a form by ID and create a new spreadsheet.
var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
var 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เพิ่มรายการคำถามใหม่ต่อท้าย เพื่อให้ผู้ตอบเลือก 1 ตัวเลือกจากรายการแบบเลื่อนลง
addMultipleChoiceItem()MultipleChoiceItemเพิ่มรายการคำถามใหม่ที่อนุญาตให้ผู้ตอบเลือก 1 ตัวเลือกจากรายการปุ่มตัวเลือกหรือช่อง "อื่นๆ" (ไม่บังคับ)
addPageBreakItem()PageBreakItemเพิ่มรายการเลย์เอาต์ใหม่ที่ทำเครื่องหมายจุดเริ่มต้นของหน้า
addParagraphTextItem()ParagraphTextItemเพิ่มรายการคำถามใหม่ที่ให้ผู้ตอบป้อนบล็อกข้อความได้
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รับสินค้าตามรหัสที่ระบุ
getItems()Item[]รับอาร์เรย์ของรายการทั้งหมดในแบบฟอร์ม
getItems(itemType)Item[]รับอาร์เรย์ของรายการทั้งหมดในประเภทที่ระบุ
getPublishedUrl()Stringรับ URL ที่ใช้เพื่อตอบแบบฟอร์มได้
getResponse(responseId)FormResponseรับการตอบกลับแบบฟอร์มเดียวตามรหัสการตอบกลับ
getResponses()FormResponse[]รับอาร์เรย์ของคำตอบทั้งหมดของแบบฟอร์ม
getResponses(timestamp)FormResponse[]รับอาร์เรย์ของการตอบกลับทั้งหมดของแบบฟอร์มหลังจากวันที่และเวลาที่ระบุ
getShuffleQuestions()Booleanพิจารณาว่าลำดับของคำถามในแต่ละหน้าของแบบฟอร์มเป็นแบบสุ่มหรือไม่
getSummaryUrl()Stringรับ URL ที่ใช้เพื่อดูสรุปการตอบกลับของแบบฟอร์ม
getTitle()Stringรับชื่อของแบบฟอร์ม
hasLimitOneResponsePerUser()Booleanกําหนดว่าแบบฟอร์มจะอนุญาตให้ตอบเพียง 1 คำตอบต่อผู้ตอบ 1 คนหรือไม่
hasProgressBar()Booleanกําหนดว่าแบบฟอร์มจะแสดงแถบความคืบหน้าหรือไม่
hasRespondAgainLink()Booleanกำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อส่งคำตอบอื่นหลังจากที่ผู้ตอบกรอกแบบฟอร์มเสร็จแล้วหรือไม่
isAcceptingResponses()Booleanระบุว่าแบบฟอร์มกำลังรับคำตอบอยู่หรือไม่
isPublishingSummary()Booleanกำหนดว่าแบบฟอร์มจะแสดงลิงก์เพื่อดูข้อมูลสรุปของคำตอบหลังจากที่ผู้ตอบกรอกแบบฟอร์มเสร็จแล้วหรือไม่
isQuiz()Booleanระบุว่าแบบฟอร์มเป็นแบบทดสอบหรือไม่
moveItem(from, to)Itemย้ายรายการที่ดัชนีหนึ่งๆ ระหว่างรายการทั้งหมดในแบบฟอร์มไปยังดัชนีอื่นที่กำหนดไว้
moveItem(item, toIndex)Itemย้ายรายการที่ระบุไปยังดัชนีที่กำหนดจากรายการทั้งหมดในแบบฟอร์ม
removeDestination()Formยกเลิกการลิงก์แบบฟอร์มจากปลายทางการตอบกลับปัจจุบัน
removeEditor(emailAddress)Formนำผู้ใช้ที่ระบุออกจากรายชื่อเอดิเตอร์ของ Form
removeEditor(user)Formนำผู้ใช้ที่ระบุออกจากรายชื่อเอดิเตอร์ของ Form
requiresLogin()Booleanระบุว่าแบบฟอร์มกำหนดให้ผู้ตอบต้องลงชื่อเข้าสู่ระบบบัญชีในโดเมนหรือโดเมนย่อยเดียวกันก่อนที่จะตอบ
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ตั้งค่าว่าแบบฟอร์มอนุญาตให้มีคำตอบเดียวต่อผู้ตอบ 1 คนหรือไม่
setProgressBar(enabled)Formตั้งค่าว่าแบบฟอร์มจะมีแถบความคืบหน้าหรือไม่
setPublishingSummary(enabled)Formตั้งค่าว่าจะให้แบบฟอร์มแสดงลิงก์เพื่อดูข้อมูลสรุปของคำตอบหลังจากที่ผู้ตอบส่งแบบฟอร์มแล้วหรือไม่
setRequireLogin(requireLogin)Formตั้งค่าว่าแบบฟอร์มกำหนดให้ผู้ตอบต้องลงชื่อเข้าสู่ระบบบัญชีในโดเมนหรือโดเมนย่อยเดียวกันก่อนที่จะตอบ
setShowLinkToRespondAgain(enabled)Formตั้งค่าว่าแบบฟอร์มจะแสดงลิงก์เพื่อส่งคำตอบอื่นหลังจากที่ผู้ตอบกรอกแบบฟอร์มเสร็จแล้วหรือไม่
setShuffleQuestions(shuffle)Formตั้งค่าว่าจะสุ่มลำดับของคำถามในหน้าเว็บแต่ละหน้าของแบบฟอร์มหรือไม่
setTitle(title)Formตั้งชื่อแบบฟอร์ม
shortenFormUrl(url)Stringแปลง URL แบบยาวสำหรับแบบฟอร์มเป็น URL แบบสั้น
submitGrades(responses)Formส่งคะแนนสำหรับ FormResponses ที่ระบุ

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

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

// Sets the title 'Where did you celebrate New Year's?'
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 หากผู้ใช้อยู่ในรายการผู้ดูอยู่แล้ว วิธีนี้จะโปรโมตผู้ใช้ออกจากรายการผู้ดู

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

addEditor(user)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
userUserตัวแทนของผู้ใช้ที่จะเพิ่ม

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

addEditors(emailAddresses)

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

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

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
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);
}

พารามิเตอร์

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

การขว้าง

Error — หากไม่มีสินค้าในแบบฟอร์ม

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

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

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

deleteResponse(responseId)

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
idIntegerรหัสของสินค้า

รีเทิร์น

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

พารามิเตอร์

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

รีเทิร์น

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)

รับการตอบกลับแบบฟอร์มเดียวตามรหัสการตอบกลับ ดูรหัสคำตอบได้จาก FormResponse.getId()

พารามิเตอร์

ชื่อTypeคำอธิบาย
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)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
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 ที่ใช้เพื่อดูสรุปการตอบกลับของแบบฟอร์ม หากไม่ได้ตั้งค่า setPublishingSummary(enabled) เป็น 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()

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

รีเทิร์น

Booleantrue หากแบบฟอร์มอนุญาตให้ผู้ตอบเพียง 1 คนต่อผู้ตอบ 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

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
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);

พารามิเตอร์

ชื่อTypeคำอธิบาย
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();

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

removeEditor(emailAddress)

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

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

removeEditor(user)

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

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
userUserตัวแทนของผู้ใช้ที่จะนำออก

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

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

รีเทิร์น

Booleantrue หากแบบฟอร์มกำหนดให้ผู้ใช้ต้องเข้าสู่ระบบ หรือ false หากไม่


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

พารามิเตอร์

ชื่อTypeคำอธิบาย
enabledBooleantrue หากแบบฟอร์มควรยอมรับคำขอ false หากไม่ควรรับคำตอบ

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
collectBooleantrue หากแบบฟอร์มควรรวบรวมอีเมล false หากไม่ได้รวบรวม

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

setDescription(description)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
descriptionStringคำอธิบายใหม่ของแบบฟอร์ม

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

setDestination(type, id)

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

การขว้าง

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

setLimitOneResponsePerUser(enabled)

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

setPublishingSummary(enabled)

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
requireLoginBooleantrue หากแบบฟอร์มกำหนดให้ผู้ใช้ต้องเข้าสู่ระบบ หรือ false หากไม่ได้

รีเทิร์น

Form — รูปแบบปัจจุบัน (สำหรับเชน)

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

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

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

setShowLinkToRespondAgain(enabled)

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

setShuffleQuestions(shuffle)

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

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

setTitle(title)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
titleStringชื่อใหม่ของแบบฟอร์ม

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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

shortenFormUrl(url)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
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() เพื่อป้องกันไม่ให้เกิดการวนซ้ำ

พารามิเตอร์

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

รีเทิร์น

FormForm นี้สำหรับการทำเชน

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

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

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