Class FormResponse

FormResponse

पूरे फ़ॉर्म का जवाब. FormResponse का इस्तेमाल तीन तरह से किया जा सकता है: जवाब देने वाले व्यक्ति के सबमिट किए गए जवाबों को ऐक्सेस करना (getItemResponses() देखें), प्रोग्राम के हिसाब से फ़ॉर्म का जवाब सबमिट करना (withItemResponse(response) और submit() देखें), और दिए गए जवाबों का इस्तेमाल करके फ़ील्ड में अपने-आप भरने वाले फ़ॉर्म का यूआरएल जनरेट करना. Form से FormResponse बनाए या ऐक्सेस किए जा सकते हैं.

// 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ऐसा यूआरएल जनरेट करता है जिसका इस्तेमाल पहले सबमिट किए जा चुके जवाब में बदलाव करने के लिए किया जा सकता है.
getGradableItemResponses()ItemResponse[]फ़ॉर्म में दिए गए सभी आइटम के रिस्पॉन्स, उसी क्रम में दिखाए जाते हैं जिस क्रम में वे फ़ॉर्म में दिखते हैं.
getGradableResponseForItem(item)ItemResponseकिसी दिए गए आइटम के लिए, फ़ॉर्म में दिए गए जवाब में मौजूद आइटम का रिस्पॉन्स मिलता है.
getId()Stringफ़ॉर्म में दिए गए जवाब के आईडी की जानकारी मिलती है.
getItemResponses()ItemResponse[]फ़ॉर्म में दिए गए सभी आइटम के रिस्पॉन्स, उसी क्रम में दिखाए जाते हैं जिस क्रम में वे फ़ॉर्म में दिखते हैं.
getRespondentEmail()Stringअगर Form.setCollectEmail(collect) सेटिंग चालू हो, तो जवाब सबमिट करने वाले व्यक्ति के ईमेल पते की जानकारी मिलती है.
getResponseForItem(item)ItemResponseकिसी दिए गए आइटम के लिए, इस फ़ॉर्म में दिए गए जवाब में, आइटम का रिस्पॉन्स मिलता है.
getTimestamp()Dateफ़ॉर्म जवाब सबमिट करने के लिए टाइमस्टैंप मिलता है.
submit()FormResponseजवाब सबमिट करता है.
toPrefilledUrl()Stringफ़ॉर्म के लिए एक यूआरएल जनरेट करता है, जिसमें इस फ़ॉर्म में दिए गए जवाबों के आधार पर जवाब पहले से भरे होते हैं.
withItemGrade(gradedResponse)FormResponseदिए गए आइटम के जवाब के ग्रेड को फ़ॉर्म में दिए गए जवाब में जोड़ता है.
withItemResponse(response)FormResponseदिए गए आइटम के जवाब को फ़ॉर्म में दिए गए जवाब में जोड़ता है.

ज़्यादा जानकारी के साथ दस्तावेज़

getEditResponseUrl()

ऐसा यूआरएल जनरेट करता है जिसका इस्तेमाल पहले सबमिट किए जा चुके जवाब में बदलाव करने के लिए किया जा सकता है. अगर 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 — सबमिट किए गए जवाब को बदलने के लिए यूआरएल.

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या ज़्यादा स्कोप से अनुमति देने की ज़रूरत होती है:

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

फ़ॉर्म के लिए एक यूआरएल जनरेट करता है, जिसमें इस फ़ॉर्म में दिए गए जवाबों के आधार पर जवाब पहले से भरे होते हैं.

// 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 — पहले से भरे गए जवाबों वाले फ़ॉर्म का यूआरएल.

अनुमति देना

इस तरीके का इस्तेमाल करने वाली स्क्रिप्ट को, इनमें से एक या ज़्यादा स्कोप से अनुमति देने की ज़रूरत होती है:

  • 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