Class FormResponse

FormResponse

تمثّل هذه السمة ردًا على النموذج ككل. يمكن استخدام FormResponse بثلاث طرق: للوصول إلى الإجابات التي يقدّمها المجيب (راجِع getItemResponses())، وإرسال ردّ آلي إلى النموذج (راجِع withItemResponse(response) وsubmit())، وإنشاء عنوان URL للنموذج الذي يملأ مسبقًا الحقول باستخدام الإجابات المقدَّمة. يمكن إنشاء FormResponse أو الوصول إليها من Form.

// Open a form by ID and log the responses to each question.
var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
var formResponses = form.getResponses();
for (var i = 0; i < formResponses.length; i++) {
  var formResponse = formResponses[i];
  var itemResponses = formResponse.getItemResponses();
  for (var j = 0; j < itemResponses.length; j++) {
    var itemResponse = itemResponses[j];
    Logger.log('Response #%s to the question "%s" was "%s"',
        (i + 1).toString(),
        itemResponse.getItem().getTitle(),
        itemResponse.getResponse());
  }
}

الطُرق

الطريقةنوع القيمة التي يتم إرجاعهاوصف قصير
getEditResponseUrl()Stringينشئ عنوان URL يمكن استخدامه لتعديل رد تم إرساله من قبل.
getGradableItemResponses()ItemResponse[]للحصول على جميع الردود على العناصر المضمّنة في استجابة النموذج، بنفس الترتيب الذي تظهر فيه العناصر في النموذج.
getGradableResponseForItem(item)ItemResponseللحصول على ردّ العنصر المضمّن في ردّ النموذج لعنصر معيّن.
getId()Stringالحصول على رقم تعريف الرد على النموذج
getItemResponses()ItemResponse[]للحصول على جميع الردود على العناصر المضمّنة في استجابة النموذج، بنفس الترتيب الذي تظهر فيه العناصر في النموذج.
getRespondentEmail()Stringيمكن الحصول على عنوان البريد الإلكتروني للشخص الذي أرسل ردًا، إذا كان الإعداد Form.setCollectEmail(collect) مفعّلاً.
getResponseForItem(item)ItemResponseيمكن الحصول على ردّ العنصر المضمّن في ردّ النموذج هذا لعنصر معيّن.
getTimestamp()Dateتلقّي الطابع الزمني لإرسال الرد على النموذج.
submit()FormResponseإرسال الرد.
toPrefilledUrl()Stringإنشاء عنوان URL للنموذج الذي يتم فيه ملء الإجابات مسبقًا استنادًا إلى الإجابات في رد النموذج هذا.
withItemGrade(gradedResponse)FormResponseلإضافة درجات الرد المحدد على العنصر إلى الرد على النموذج.
withItemResponse(response)FormResponseلإضافة الرد على العنصر إلى الرد على النموذج.

الوثائق التفصيلية

getEditResponseUrl()

ينشئ عنوان 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

getGradableItemResponses()

للحصول على جميع الردود على العناصر المضمّنة في استجابة النموذج، بنفس الترتيب الذي تظهر فيه العناصر في النموذج. تعمل هذه الطريقة بشكل مشابه لدالة getItemResponses()، ولكن للسماح بوضع درجات لإجابة غير موجودة، فإنها تعرض ItemResponse إذا كان من الممكن وضع درجة 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()}`);
  }
}

استرجاع الكرة

ItemResponse[] - مصفوفة من الردود لكل عنصر سؤال داخل النموذج يمكن أن يحصل المجيب على تقييم له.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على تفويض باستخدام واحد أو أكثر من النطاقات التالية:

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

getGradableResponseForItem(item)

للحصول على ردّ العنصر المضمّن في ردّ النموذج لعنصر معيّن. تعمل هذه الطريقة على غرار طريقة getResponseForItem(item)، ولكن للسماح بوضع درجات لإجابة غير متوفّرة، فإنها تعرض ItemResponse إذا كان من الممكن وضع درجات لـ 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()}`);
}

المَعلمات

الاسمTypeالوصف
itemItem

استرجاع الكرة

ItemResponse - الاستجابة لعنصر معيّن، أو null في حال عدم وجود أي عنصر وعدم وضع درجات له.


getId()

الحصول على رقم تعريف الرد على النموذج تعرض هذه الطريقة 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

getItemResponses()

للحصول على جميع الردود على العناصر المضمّنة في استجابة النموذج، بنفس الترتيب الذي تظهر فيه العناصر في النموذج. إذا لم تتضمّن استجابة النموذج استجابة لـ TextItem أو DateItem أو TimeItem أو ParagraphTextItem محدّدَين، سيحتوي العنصر ItemResponse التي يتم عرضها لهذا العنصر على سلسلة فارغة كاستجابة. إذا حذفت استجابة النموذج ردًا لأي نوع عنصر آخر، فإن هذه الطريقة تستبعد هذا العنصر من الصفيف الذي يتم عرضه.

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

استرجاع الكرة

ItemResponse[] - مصفوفة من الردود لكل عنصر سؤال داخل النموذج الذي قدّم المجيب إجابة عنه.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على تفويض باستخدام واحد أو أكثر من النطاقات التالية:

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

getRespondentEmail()

يمكن الحصول على عنوان البريد الإلكتروني للشخص الذي أرسل ردًا، إذا كان الإعداد 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

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

المَعلمات

الاسمTypeالوصف
itemItem

استرجاع الكرة

ItemResponse: الردّ على عنصر معيّن أو null في حال عدم توفّره


getTimestamp()

تلقّي الطابع الزمني لإرسال الرد على النموذج.

بالنسبة إلى الرد على النموذج الذي أنشأه النص البرمجي ولم يتم إرساله بعد، تعرض هذه الطريقة القيمة 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();

استرجاع الكرة

FormResponse - تم حفظ رد تم إنشاؤه حديثًا في مخزن الردود في النموذج.

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على تفويض باستخدام واحد أو أكثر من النطاقات التالية:

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

toPrefilledUrl()

إنشاء عنوان 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

withItemGrade(gradedResponse)

لإضافة درجات الرد المحدد على العنصر إلى الرد على النموذج. لا تنطبق هذه الطريقة إلا على ردود النماذج التي سبق إرسالها، ولا تؤثر إلا على الدرجات المخزَّنة بعد إرسالها. تعمل هذه الطريقة أيضًا على تعديل درجات استجابة العنصر فقط، فهي لا تؤثر على الاستجابة الفعلية (نظرًا لإرسال الرد بالفعل). إذا تم استدعاء هذه الطريقة عدة مرات لنفس العنصر، فسيتم الاحتفاظ بالدرجة الأخيرة فقط. إذا كان عنصر ItemResponse لا يحتوي على درجات، فسوف تزيل هذه الطريقة درجات العنصر.

// Programmatically award partial credit for a given response
var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
var formResponses = form.getResponses();
var formItems = form.getItems();
for (var i = 0; i < formResponses.length; i++) {
  var formResponse = formResponses[i];
  for (var j = 0; j < formItems.length; j++) {
    var item = formItems[j];
    var points = item.asMultipleChoiceItem().getPoints();
    var itemResponse = formResponse.getGradableResponseForItem(item);
    Logger.log('Award half credit for answers containing the word "Kennedy"');
    var answer = itemResponse.getResponse();
    if (answer != null && answer.includes('Kennedy')) {
      itemResponse.setScore(points / 2);
      formResponse.withItemGrade(itemResponse);
    }
  }
}
form.submitGrades(formResponses);

المَعلمات

الاسمTypeالوصف
gradedResponseItemResponse

استرجاع الكرة

FormResponse — جهاز FormResponse هذا للسلاسل

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على تفويض باستخدام واحد أو أكثر من النطاقات التالية:

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

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

المَعلمات

الاسمTypeالوصف
responseItemResponse

استرجاع الكرة

FormResponse - جهاز FormResponse هذا للسلاسل

التفويض

تتطلب النصوص البرمجية التي تستخدم هذه الطريقة الحصول على تفويض باستخدام واحد أو أكثر من النطاقات التالية:

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