Class FormResponse

FormResponse

전체 양식에 대한 응답입니다. FormResponse는 응답자가 제출한 답변에 액세스하고 (getItemResponses() 참고) 프로그래매틱 방식으로 양식에 대한 응답을 제출하고 (withItemResponse(response)submit() 참고) 제공된 답변을 사용하여 필드를 미리 채우는 양식의 URL을 생성하는 세 가지 방법으로 사용할 수 있습니다. FormResponseForm에서 생성하거나 액세스할 수 있습니다.

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

메서드

메서드반환 유형간략한 설명
getEditResponseUrl()String이미 제출된 응답을 수정하는 데 사용할 수 있는 URL을 생성합니다.
getGradableItemResponses()ItemResponse[]항목이 양식에 표시되는 순서와 동일한 순서로 양식 응답에 포함된 모든 항목 응답을 가져옵니다.
getGradableResponseForItem(item)ItemResponse지정된 항목의 양식 응답에 포함된 항목 응답을 가져옵니다.
getId()String양식 응답의 ID를 가져옵니다.
getItemResponses()ItemResponse[]항목이 양식에 표시되는 순서와 동일한 순서로 양식 응답에 포함된 모든 항목 응답을 가져옵니다.
getRespondentEmail()StringForm.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()와 유사하게 작동하지만, 누락된 답변을 채점할 수 있도록 실제 응답이 없더라도 해당 Item을 채점할 수 있는 경우 (즉, 점수 값이 있는 경우) ItemResponse을 반환합니다. 하지만 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)와 유사하게 작동하지만 누락된 답변을 채점할 수 있도록 실제 응답이 없더라도 해당 Item를 채점할 수 있는 경우 (즉, 포인트 값이 있는 경우) ItemResponse를 반환합니다. 하지만 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()}`,
  );
}

매개변수

이름유형설명
itemItem

리턴

ItemResponse - 지정된 항목의 응답입니다. 항목이 채점되지 않았고 응답이 없는 경우 null입니다.


getId()

양식 응답의 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 - 양식 응답의 ID입니다. 양식 응답이 제출되지 않은 경우 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());
}

매개변수

이름유형설명
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
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);

매개변수

이름유형설명
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();

매개변수

이름유형설명
responseItemResponse

리턴

FormResponse - 체이닝을 위한 이 FormResponse

승인

이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.

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