Class FormResponse

FormResponse

Formun tamamına verilen yanıt. FormResponse; bir katılımcı tarafından gönderilen yanıtlara erişmek (getItemResponses() bölümüne bakın), forma programlı bir şekilde yanıt göndermek (bkz. withItemResponse(response) ve submit()) ve sağlanan yanıtları kullanarak alanları önceden dolduran form için bir URL oluşturmak olmak üzere üç şekilde kullanılabilir. FormResponse öğeleri Form aracılığıyla oluşturulabilir veya kullanılabilir.

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

Yöntemler

YöntemDönüş türüKısa açıklama
getEditResponseUrl()StringÖnceden gönderilmiş bir yanıtı düzenlemek için kullanılabilecek bir URL oluşturur.
getGradableItemResponses()ItemResponse[]Bir form yanıtında yer alan tüm öğe yanıtlarını, öğelerin formda göründüğü sırayla alır.
getGradableResponseForItem(item)ItemResponseBelirli bir öğe için form yanıtında yer alan öğe yanıtını alır.
getId()StringForm yanıtının kimliğini alır.
getItemResponses()ItemResponse[]Bir form yanıtında yer alan tüm öğe yanıtlarını, öğelerin formda göründüğü sırayla alır.
getRespondentEmail()StringForm.setCollectEmail(collect) ayarı etkinse yanıt gönderen kişinin e-posta adresini alır.
getResponseForItem(item)ItemResponseBelirli bir öğe için bu form yanıtında yer alan öğe yanıtını alır.
getTimestamp()DateForm yanıtı gönderiminin zaman damgasını alır.
submit()FormResponseYanıtı gönderir.
toPrefilledUrl()StringYanıtların bu form yanıtındaki yanıtlara göre önceden doldurulduğu form için bir URL oluşturur.
withItemGrade(gradedResponse)FormResponseBelirtilen öğe yanıtının notlarını form yanıtına ekler.
withItemResponse(response)FormResponseBelirtilen öğe yanıtını form yanıtına ekler.

Ayrıntılı belgeler

getEditResponseUrl()

Önceden gönderilmiş bir yanıtı düzenlemek için kullanılabilecek bir URL oluşturur. Form.setAllowResponseEdits(enabled) ayarı devre dışıysa bağlantı, form yanıtlarını düzenlemenin devre dışı bırakıldığını açıklayan bir sayfaya yönlendirir. Bağlantıyı ziyaret eden herkes yanıtı düzenleyebilir. Bununla birlikte, Form.setRequireLogin(requireLogin) ayarı etkinse bu kullanıcıların forma erişimi olan bir hesaba ihtiyacı vardır. Form.setCollectEmail(collect) ayarı etkinleştirilirse form, orijinal katılımcının e-posta adresi yerine yanıtı düzenleyen kullanıcının e-posta adresini kaydeder.

Komut dosyasının oluşturduğu ancak henüz gönderilmemiş bir form yanıtı için bu yöntem null değerini döndürür.

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

Return

String: Gönderilen bir yanıtı değiştirecek URL.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getGradableItemResponses()

Bir form yanıtında yer alan tüm öğe yanıtlarını, öğelerin formda göründüğü sırayla alır. Bu yöntem getItemResponses() yöntemine benzer şekilde çalışır, ancak eksik bir cevaba not verilebilmesi için, karşılık gelen Item yanıtlanabiliyorsa (ör. puan değeri varsa) gerçek bir yanıt olmasa bile ItemResponse sonucunu döndürür. Bununla birlikte, Item notlandırılabilir değilse bu yöntem, öğeyi döndürülen diziden hariç tutar.

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

Return

ItemResponse[]: Katılımcının puan alabileceği formdaki her soru öğesine verilen yanıt dizisi.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getGradableResponseForItem(item)

Belirli bir öğe için form yanıtında yer alan öğe yanıtını alır. Bu yöntem, getResponseForItem(item) yöntemine benzer şekilde çalışır ancak eksik bir cevaba not verilebilmesini sağlamak amacıyla, gerçek bir yanıt olmasa bile karşılık gelen Item notlanabiliyorsa (ör. puan değerine sahipse) bir ItemResponse döndürür. Bununla birlikte, Item derecelendirilebilir değilse bu yöntem null değerini döndürür.

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

Parametreler

AdTürAçıklama
itemItem

Return

ItemResponse: Belirli bir öğenin yanıtı veya mevcut bir öğe yoksa ve öğe not verilmediyse null.


getId()

Form yanıtının kimliğini alır. Form yanıtı gönderilmemişse bu yöntem null değerini döndürür.

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

Return

String: Form yanıtının kimliği veya form yanıtı gönderilmediyse null.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getItemResponses()

Bir form yanıtında yer alan tüm öğe yanıtlarını, öğelerin formda göründüğü sırayla alır. Form yanıtı belirli bir TextItem, DateItem, TimeItem veya ParagraphTextItem için yanıt içermiyorsa söz konusu öğe için döndürülen ItemResponse yanıt olarak boş bir dize olur. Form yanıtı başka herhangi bir öğe türünü içeren bir yanıtı atlarsa bu yöntem, söz konusu öğeyi döndürülen diziden hariç tutar.

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

Return

ItemResponse[]: Formda, katılımcının yanıt sağladığı her soru öğesine verilen yanıt dizisi.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getRespondentEmail()

Form.setCollectEmail(collect) ayarı etkinse yanıt gönderen kişinin e-posta adresini alır.

Komut dosyasının oluşturduğu ancak henüz gönderilmemiş bir form yanıtı için bu yöntem null değerini döndürür.

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

Return

String — Varsa bu yanıtı gönderen kişinin e-posta adresi veya komut dosyası bu yanıtı oluşturduysa ancak henüz göndermediyse null.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

getResponseForItem(item)

Belirli bir öğe için bu form yanıtında yer alan öğe yanıtını alır.

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

Parametreler

AdTürAçıklama
itemItem

Return

ItemResponse: Belirli bir öğenin yanıtı. Yoksa null.


getTimestamp()

Form yanıtı gönderiminin zaman damgasını alır.

Komut dosyasının oluşturduğu ancak henüz gönderilmemiş bir form yanıtı için bu yöntem null değerini döndürür.

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

Return

Date: Bu yanıtın gönderildiği zaman damgası veya komut dosyası bu yanıtı oluşturup henüz göndermediyse null.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

submit()

Yanıtı gönderir. Yanıt zaten gönderilmişse bir komut dosyası istisnası oluşturur.

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

Return

FormResponse: Formun yanıt deposuna kaydedilen yeni oluşturulmuş yanıt.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

toPrefilledUrl()

Yanıtların bu form yanıtındaki yanıtlara göre önceden doldurulduğu form için bir URL oluşturur.

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

Return

String: Önceden doldurulmuş yanıtları içeren bir formun URL'si.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

withItemGrade(gradedResponse)

Belirtilen öğe yanıtının notlarını form yanıtına ekler. Bu yöntem yalnızca önceden gönderilmiş form yanıtları için geçerlidir ve depolanan notları yalnızca gönderildikten sonra etkiler. Bu yöntem ayrıca yalnızca öğe yanıtının notlarını da günceller; gerçek yanıtı etkilemez (yanıt zaten gönderildiğinden). Bu yöntem aynı öğe için birden çok kez çağrılırsa yalnızca son not korunur. ItemResponse hiçbir not içermiyorsa bu yöntem, öğenin aldığı notları kaldırır.

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

Parametreler

AdTürAçıklama
gradedResponseItemResponse

Return

FormResponse — bu FormResponse, zincirleme bağlantı için

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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

withItemResponse(response)

Belirtilen öğe yanıtını form yanıtına ekler. Bu yöntem yalnızca komut dosyasının oluşturduğu ancak henüz göndermediği form yanıtları için geçerlidir. Depolanan yanıtları etkilemez. Bu yöntem, aynı öğe için birden çok kez çağrılırsa yalnızca son öğe yanıtı korunur.

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

Parametreler

AdTürAçıklama
responseItemResponse

Return

FormResponse — Bu FormResponse, zincirleme bağlantı için.

Yetkilendirme

Bu yöntemi kullanan komut dosyaları, aşağıdaki kapsamların biri veya daha fazlasıyla yetkilendirme gerektirir:

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