تمثّل هذه السمة ردًا على النموذج ككل. يمكن استخدام 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(), ); } }
الطُرق
الطريقة | نوع القيمة التي يتم إرجاعها | وصف قصير |
---|---|---|
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)
تضيف هذه الطريقة درجات ردّ العنصر المحدّد إلى ردّ النموذج. لا تنطبق هذه الطريقة إلا على ردود النماذج التي تم إرسالها، ولا تؤثّر إلا في الدرجات المخزّنة بعد إرسالها. لا تعدّل هذه الطريقة أيضًا سوى درجات ردّ العنصر، ولا تؤثّر في الرد الفعلي (بما أنّ الرد قد تم إرساله). إذا تم استدعاء هذه الطريقة عدة مرات للعنصر نفسه، سيتم الاحتفاظ بالدرجة الأخيرة فقط. إذا كان 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