תשובה לטופס כולו. אפשר להשתמש בForm
בשלוש דרכים: כדי לגשת לתשובות שנשלחו על ידי המשיב (ראו get
), כדי לשלוח תשובה לטופס באופן פרוגרמטי (ראו with
ו-submit()
) וכדי ליצור כתובת URL לטופס שבה השדות ימולאו מראש באמצעות התשובות שסופקו. אפשר ליצור Form
או לגשת אליהם מתוך Form
.
// Open a form by ID and log the responses to each question. const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const formResponses = form.getResponses(); for (let i = 0; i < formResponses.length; i++) { const formResponse = formResponses[i]; const itemResponses = formResponse.getItemResponses(); for (let j = 0; j < itemResponses.length; j++) { const itemResponse = itemResponses[j]; Logger.log( 'Response #%s to the question "%s" was "%s"', (i + 1).toString(), itemResponse.getItem().getTitle(), itemResponse.getResponse(), ); } }
Methods
שיטה | סוג הערך שמוחזר | תיאור קצר |
---|---|---|
get | String | יוצר כתובת URL שאפשר להשתמש בה כדי לערוך תשובה שכבר נשלחה. |
get | Item | מחזירה את כל התשובות לפריטים שכלולות בתגובה לטופס, באותו סדר שבו הפריטים מופיעים בטופס. |
get | Item | מקבל את התשובה לפריט שנכללת בתשובה לטופס עבור פריט נתון. |
get | String | מחזירה את המזהה של התשובה לטופס. |
get | Item | מחזירה את כל התשובות לפריטים שכלולות בתגובה לטופס, באותו סדר שבו הפריטים מופיעים בטופס. |
get | String | מקבל את כתובת האימייל של האדם ששלח את התשובה, אם ההגדרה Form.setCollectEmail(collect) מופעלת. |
get | Item | מחזירה את התשובה לפריט שכלולה בתשובה הזו לטופס עבור פריט נתון. |
get | Date | מקבל את חותמת הזמן של שליחת תשובה לטופס. |
submit() | Form | שליחת התשובה. |
to | String | יוצר כתובת URL לטופס שבו התשובות מולאו מראש על סמך התשובות בטופס הזה. |
with | Form | הפונקציה מוסיפה את הציונים של תשובת הפריט שצוינה לתשובה בטופס. |
with | Form | הפונקציה מוסיפה את התשובה שצוינה לפריט לתשובה בטופס. |
תיעוד מפורט
get Edit Response Url()
יוצר כתובת URL שאפשר להשתמש בה כדי לערוך תשובה שכבר נשלחה. אם ההגדרה Form.setAllowResponseEdits(enabled)
מושבתת, הקישור מוביל לדף שבו מוסבר שאין אפשרות לערוך את התשובות בטופס. כל מי שנכנס לקישור יכול לערוך את התשובה, אבל אם ההגדרה
מופעלת, הוא צריך חשבון עם גישה לטופס. אם ההגדרה Form.setRequireLogin(requireLogin)Form.setCollectEmail(collect)
מופעלת, בטופס נשמרת כתובת האימייל של המשתמש שערך את התשובה במקום כתובת האימייל של המשיב המקורי.
אם הסקריפט יצר תשובה לטופס אבל עדיין לא שלח אותה, הפונקציה הזו מחזירה את הערך
null
.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets the first form response. const formResponse = form.getResponses()[0]; // Gets the edit URL for the first form response and logs it to the console. const editUrl = formResponse.getEditResponseUrl(); console.log(editUrl);
חזרה
String
— כתובת ה-URL לשינוי תשובה שנשלחה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
get Gradable Item Responses()
מחזירה את כל התשובות לפריטים שכלולות בתגובה לטופס, באותו סדר שבו הפריטים מופיעים בטופס. השיטה הזו פועלת באופן דומה לשיטה get
, אבל כדי לאפשר מתן ציון לתשובה חסרה, היא עדיין מחזירה Item
אם אפשר לתת ציון ל-Item
המתאים (כלומר, יש לו ערך נקודות), גם אם אין תשובה בפועל. עם זאת, אם אי אפשר לתת ציון לפריט Item
, הפריט הזה לא ייכלל במערך המוחזר של השיטה.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets an array of the form's responses. const formResponses = form.getResponses(); // Gets the item responses contained in each form response. for (const formResponse of formResponses) { const gradableItemsResponses = formResponse.getGradableItemResponses(); // Logs the title and score for each item response to the console. for (const gradableItemsResponse of gradableItemsResponses) { console.log(`${gradableItemsResponse.getItem().getTitle()} score ${gradableItemsResponse.getScore()}`); } }
חזרה
Item
— מערך של תשובות לכל פריט שאלה בטופס, שעבורו המשיב יכול לקבל ציון.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
get Gradable Response For Item(item)
מקבל את התשובה לפריט שנכללת בתשובה לטופס עבור פריט נתון. השיטה הזו פועלת באופן דומה ל-get
, אבל כדי לאפשר מתן ציון לתשובה חסרה, היא עדיין מחזירה Item
אם אפשר לתת ציון ל-Item
המתאים (כלומר, יש לו ערך נקודות), גם אם אין תשובה בפועל. עם זאת, אם אי אפשר לתת ציון ל-Item
, הפונקציה הזו מחזירה null
.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets an array of the form's responses. const formResponses = form.getResponses(); // Gets the item responses contained in a form response. for (const formResponse of formResponses) { const formItemResponses = formResponse.getGradableItemResponses(); // Logs the title and score for responses to the first item of the form. const itemResponse = formResponse.getGradableResponseForItem( formItemResponses[0].getItem(), ); console.log( `${itemResponse.getItem().getTitle()} score ${itemResponse.getScore()}`, ); }
פרמטרים
שם | סוג | תיאור |
---|---|---|
item | Item |
חזרה
Item
– התגובה לפריט נתון, או null
אם לא קיימת תגובה והפריט לא קיבל ציון.
get Id()
מחזירה את המזהה של התשובה לטופס. השיטה הזו מחזירה null
אם התשובה לטופס לא נשלחה.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets an array of the form's responses. const formResponses = form.getResponses(); // Loops through the form responses and logs the ID for each form response to // the console. for (const formResponse of formResponses) { console.log(`Response ID: ${formResponse.getId()}`); }
חזרה
String
– המזהה של התשובה לטופס, או null
אם התשובה לטופס לא נשלחה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
get Item Responses()
מחזירה את כל התשובות לפריטים שכלולות בתגובה לטופס, באותו סדר שבו הפריטים מופיעים בטופס. אם התגובה בטופס לא מכילה תגובה לText
, לDate
, לTime
או לParagraph
, התגובה שתחזור עבור הפריט הזה תהיה מחרוזת ריקה.Item
אם התשובה בטופס לא כוללת תשובה לפריט מסוג אחר, הפריט הזה לא ייכלל במערך שמוחזר על ידי השיטה הזו.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets the responses to the form. const formResponses = form.getResponses(); // Iterates over the responses. for (const formResponse of formResponses) { // Gets the item responses from each form response. const itemResponses = formResponse.getItemResponses(); // Iterates over the item responses. for (const itemResponse of itemResponses) { // Logs the items' questions and responses to the console. console.log( `Response to the question '${itemResponse.getItem().getTitle()}' was '${itemResponse.getResponse()}'`); } }
חזרה
Item
— מערך של תשובות לכל פריט שאלה בטופס, שעליו המשיב
סיפק תשובה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
get Respondent Email()
מקבל את כתובת האימייל של האדם ששלח את התשובה, אם ההגדרה Form.setCollectEmail(collect)
מופעלת.
אם הסקריפט יצר תשובה לטופס אבל עדיין לא שלח אותה, הפונקציה הזו מחזירה את הערך
null
.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets an array of the form's responses. const formResponses = form.getResponses(); // Loops through the responses and logs each respondent's email to the console. // To collect respondent emails, ensure that Form.setCollectEmail(collect) is // set to true. for (const formResponse of formResponses) { console.log(`Respondent Email: ${formResponse.getRespondentEmail()}`); }
חזרה
String
– כתובת האימייל של האדם ששלח את התשובה הזו, אם היא זמינה, או null
אם הסקריפט יצר את התשובה הזו אבל עדיין לא שלח אותה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
get Response For Item(item)
מחזירה את התשובה לפריט שכלולה בתשובה הזו לטופס עבור פריט נתון.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets the first item on the form. const item = form.getItems()[0]; // Gets an array of the form's responses. const formResponses = form.getResponses(); // Loops through the responses and logs each response to the first item to the // console. for (const formResponse of formResponses) { const itemResponse = formResponse.getResponseForItem(item); console.log(itemResponse.getResponse()); }
פרמטרים
שם | סוג | תיאור |
---|---|---|
item | Item |
חזרה
Item
– התגובה לפריט נתון, או null
אם לא קיימת תגובה.
get Timestamp()
מקבל את חותמת הזמן של שליחת תשובה לטופס.
אם הסקריפט יצר תשובה לטופס אבל עדיין לא שלח אותה, הפונקציה הזו מחזירה את הערך
null
.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets an array of the form's responses. const formResponses = form.getResponses(); // Loops through the responses and logs the timestamp of each response to the // console. for (const formResponse of formResponses) { console.log(`Timestamp: ${formResponse.getTimestamp()}`); }
חזרה
Date
— חותמת הזמן שבה התשובה הזו נשלחה, או null
אם הסקריפט
יצר את התשובה הזו אבל עדיין לא שלח אותה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
submit()
שליחת התשובה. אם התשובה כבר נשלחה, הפונקציה מחזירה חריגה בסקריפט.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Creates an empty response for the form. const formResponse = form.createResponse(); // Submits an empty response. formResponse.submit();
חזרה
Form
– תגובה חדשה שנוצרה ונשמרה במאגר התגובות של הטופס.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
to Prefilled Url()
יוצר כתובת URL לטופס שבו התשובות מולאו מראש על סמך התשובות בטופס הזה.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Gets the first form response. const formResponse = form.getResponses()[0]; // Generates and logs the URL of a pre-filled form response based on the answers // of the first form response. const prefilledUrl = formResponse.toPrefilledUrl(); console.log(prefilledUrl);
חזרה
String
— כתובת ה-URL של טופס עם תשובות שמולאו מראש.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
with Item Grade(gradedResponse)
הפונקציה מוסיפה את הציונים של תשובת הפריט שצוינה לתשובה בטופס. השיטה הזו חלה רק על תשובות בטופס שכבר נשלחו, ומשפיעה רק על ציונים שנשמרו אחרי שהם נשלחו. בנוסף, ה-method הזה מעדכן רק את הציונים של התשובה לפריט, ולא משפיע על התשובה עצמה (כי התשובה כבר נשלחה). אם קוראים לשיטה הזו כמה פעמים עבור אותו פריט, רק הציון האחרון נשמר. אם ה-ItemResponse לא מכיל ציונים, השיטה הזו מסירה את הציונים של הפריט.
// Programmatically award partial credit for a given response const form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); const formResponses = form.getResponses(); const formItems = form.getItems(); for (const formResponse of formResponses) { for (const item of formItems) { const points = item.asMultipleChoiceItem().getPoints(); const itemResponse = formResponse.getGradableResponseForItem(item); Logger.log('Award half credit for answers containing the word "Kennedy"'); const answer = itemResponse.getResponse(); if (answer?.includes('Kennedy')) { itemResponse.setScore(points / 2); formResponse.withItemGrade(itemResponse); } } } form.submitGrades(formResponses);
פרמטרים
שם | סוג | תיאור |
---|---|---|
graded | Item |
חזרה
Form
— Form
הזה, לשרשור
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
with Item Response(response)
הפונקציה מוסיפה את התשובה שצוינה לפריט לתשובה בטופס. השיטה הזו חלה רק על תשובות לטופס שהסקריפט יצר אבל עדיין לא שלח. היא לא יכולה להשפיע על תשובות שנשמרו. אם קוראים לשיטה הזו כמה פעמים עבור אותו פריט, רק התגובה האחרונה של הפריט נשמרת.
// Opens the Forms file by its ID. // If you created your script from within a Google Forms file, you can // use FormApp.getActiveForm() instead. // TODO(developer): Replace the ID with your own. const form = FormApp.openById('abc123456'); // Creates a response for the form. const formResponse = form.createResponse(); // Appends a checkbox item to the form. const item = form.addCheckboxItem(); // Sets the title of the item to 'Which items are ice cream flavors?' item.setTitle('Which items are ice cream flavors?'); // Sets choices for the item. item.setChoices([ item.createChoice('Vanilla'), item.createChoice('Strawberry'), item.createChoice('Brick'), ]); // Creates a response for the item. const response = item.createResponse(['Vanilla', 'Strawberry']); // Adds the item response to the form response. formResponse.withItemResponse(response); // Submits the form response. formResponse.submit();
פרמטרים
שם | סוג | תיאור |
---|---|---|
response | Item |
חזרה
Form
— Form
הזה, לשרשור.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms