Class ItemResponse
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
항목응답
양식 내의 한 가지 질문 항목에 대한 응답입니다. 항목 응답은 FormResponse
에서 액세스할 수 있으며 응답자에게 질문에 답변하도록 요청하는 모든 Item
에서 만들 수 있습니다.
// 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(),
);
}
}
자세한 문서
getFeedback()
응답자가 제출한 답변에 대해 제공된 의견을 가져옵니다.
리턴
Object
: 질문 항목의 QuizFeedback
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getItem()
이 응답이 답하는 질문 항목을 가져옵니다.
리턴
Item
: 이 대답이 답하는 질문 항목
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getResponse()
응답자가 제출한 답변을 가져옵니다. 대부분의 유형의 질문 항목의 경우 String
이 반환됩니다.
CheckboxItem
질문의 경우 응답자의 선택사항이 포함된 String[]
배열을 반환합니다. 배열의 문자열 순서는 다를 수 있습니다.
GridItem
질문의 경우 색인이 n
인 답변이 그리드의 n + 1
행에 있는 질문에 해당하는 String[]
배열을 반환합니다. 응답자가 그리드의 질문에 답변하지 않은 경우 해당 답변은 ''
로 반환됩니다.
CheckboxGridItem
질문의 경우 행 색인 n
의 답변이 체크박스 그리드의 행 n + 1
에 있는 질문에 해당하는 String[][]
배열을 반환합니다. 응답자가 그리드의 질문에 답변하지 않은 경우 해당 답변은 ''
로 반환됩니다.
리턴
Object
: 질문 항목에 대한 답변의 String
, String[]
또는 String[][]
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
getScore()
응답자가 제출한 답변의 점수를 가져옵니다.
리턴
Object
: 질문 항목의 점수를 나타내는 Double
입니다.
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setFeedback(feedback)
응답자가 제출한 답변에 대해 표시할 의견을 설정합니다.
이 메서드는 업데이트된 FormResponses로 Form.submitGrades(responses)
가 호출될 때까지 실제로 Forms에 의견을 저장하지 않습니다. 예를 보려면 setScore()
을 참고하세요.
매개변수
리턴
ItemResponse
: 체이닝을 위한 ItemResponse
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
setScore(score)
응답자가 제출한 답변의 점수를 설정합니다. null 값은 기존 점수를 삭제합니다.
이 메서드는 업데이트된 FormResponses로 Form.submitGrades(responses)
가 호출될 때까지 실제로 Forms에 점수를 저장하지 않습니다.
// For a multiple choice question with options: "Always true", "Sometimes true",
// and "Never", award half credit for responses that answered "Sometimes true".
const formResponses = FormApp.getActiveForm().getResponses();
// Go through each form response
for (let i = 0; i < formResponses.length; i++) {
const response = formResponses[i];
const items = FormApp.getActiveForm().getItems();
// Assume it's the first item
const item = items[0];
const itemResponse = response.getGradableResponseForItem(item);
// Give half credit for "Sometimes true".
if (itemResponse != null && itemResponse.getResponse() === 'Sometimes true') {
const points = item.asMultipleChoiceItem().getPoints();
itemResponse.setScore(points * 0.5);
// This saves the grade, but does not submit to Forms yet.
response.withItemGrade(itemResponse);
}
}
// Grades are actually submitted to Forms here.
FormApp.getActiveForm().submitGrades(formResponses);
매개변수
리턴
ItemResponse
: 체이닝을 위한 ItemResponse
승인
이 메서드를 사용하는 스크립트에는 다음 범위 중 하나 이상의 승인이 필요합니다.
-
https://www.googleapis.com/auth/forms.currentonly
-
https://www.googleapis.com/auth/forms
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eAn \u003ccode\u003eItemResponse\u003c/code\u003e represents an answer to a single question within a Google Form.\u003c/p\u003e\n"],["\u003cp\u003eYou can access individual item responses through a \u003ccode\u003eFormResponse\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eItemResponse\u003c/code\u003e objects provide methods to get and set feedback and scores for answers, as well as retrieve the question itself and the respondent's answer.\u003c/p\u003e\n"],["\u003cp\u003eScores and feedback set using \u003ccode\u003eItemResponse\u003c/code\u003e methods must be saved to the form using \u003ccode\u003eForm.submitGrades()\u003c/code\u003e to take effect.\u003c/p\u003e\n"]]],[],null,["# Class ItemResponse\n\nItemResponse\n\nA response to one question item within a form. Item responses can be accessed from [FormResponse](/apps-script/reference/forms/form-response) and created from any [Item](/apps-script/reference/forms/item) that asks the respondent to answer a question.\n\n```javascript\n// Open a form by ID and log the responses to each question.\nconst form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');\nconst formResponses = form.getResponses();\nfor (let i = 0; i \u003c formResponses.length; i++) {\n const formResponse = formResponses[i];\n const itemResponses = formResponse.getItemResponses();\n for (let j = 0; j \u003c itemResponses.length; j++) {\n const itemResponse = itemResponses[j];\n Logger.log(\n 'Response #%s to the question \"%s\" was \"%s\"',\n (i + 1).toString(),\n itemResponse.getItem().getTitle(),\n itemResponse.getResponse(),\n );\n }\n}\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------|-------------------------------------------|-----------------------------------------------------------------------------------|\n| [getFeedback()](#getFeedback()) | `Object` | Gets the feedback that was given for the respondent's submitted answer. |\n| [getItem()](#getItem()) | [Item](/apps-script/reference/forms/item) | Gets the question item that this response answers. |\n| [getResponse()](#getResponse()) | `Object` | Gets the answer that the respondent submitted. |\n| [getScore()](#getScore()) | `Object` | Gets the score for the respondent's submitted answer. |\n| [setFeedback(feedback)](#setFeedback(Object)) | [ItemResponse](#) | Sets the feedback that should be displayed for the respondent's submitted answer. |\n| [setScore(score)](#setScore(Object)) | [ItemResponse](#) | Sets the score for the respondent's submitted answer. |\n\nDetailed documentation\n----------------------\n\n### `get``Feedback()`\n\nGets the feedback that was given for the respondent's submitted answer.\n\n#### Return\n\n\n`Object` --- a `Quiz``Feedback` for the question item\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/forms.currentonly`\n- `https://www.googleapis.com/auth/forms`\n\n*** ** * ** ***\n\n### `get``Item()`\n\nGets the question item that this response answers.\n\n#### Return\n\n\n[Item](/apps-script/reference/forms/item) --- the question item that this response answers\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/forms.currentonly`\n- `https://www.googleapis.com/auth/forms`\n\n*** ** * ** ***\n\n### `get``Response()`\n\nGets the answer that the respondent submitted. For most types of question items, this returns a\n`String`.\n\nFor [CheckboxItem](/apps-script/reference/forms/checkbox-item) questions, this returns a `String[]` array containing the\nresponder's choices. The order of the strings in the array may vary.\n\nFor [GridItem](/apps-script/reference/forms/grid-item) questions, this returns a `String[]` array in which the answer at\nindex `n` corresponds to the question at row `n + 1` in the grid. If a respondent\ndid not answer a question in the grid, that answer is returned as `''`.\n\nFor [CheckboxGridItem](/apps-script/reference/forms/checkbox-grid-item) questions, this returns a `String[][]` array in which the\nanswers at row index `n` corresponds to the question at row `n + 1` in the checkbox\ngrid. If a respondent did not answer a question in the grid, that answer is returned as `''`.\n\n#### Return\n\n\n`Object` --- a `String` or `String[]` or `String[][]` of answers to the question\nitem\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/forms.currentonly`\n- `https://www.googleapis.com/auth/forms`\n\n*** ** * ** ***\n\n### `get``Score()`\n\nGets the score for the respondent's submitted answer.\n\n#### Return\n\n\n`Object` --- a `Double` representing the score for the question item\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/forms.currentonly`\n- `https://www.googleapis.com/auth/forms`\n\n*** ** * ** ***\n\n### `set``Feedback(feedback)`\n\nSets the feedback that should be displayed for the respondent's submitted answer.\n\nThis method does not actually save the feedback in Forms until [Form.submitGrades(responses)](/apps-script/reference/forms/form#submitGrades(FormResponse)) is called with the updated FormResponses. See `set``Score()` for an example.\n\n#### Parameters\n\n| Name | Type | Description |\n|------------|----------|-------------|\n| `feedback` | `Object` | |\n\n#### Return\n\n\n[ItemResponse](#) --- a `Item``Response` for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/forms.currentonly`\n- `https://www.googleapis.com/auth/forms`\n\n*** ** * ** ***\n\n### `set``Score(score)`\n\nSets the score for the respondent's submitted answer. A null value will clear the existing\nscore.\n\nThis method does not actually save the score in Forms until [Form.submitGrades(responses)](/apps-script/reference/forms/form#submitGrades(FormResponse)) is called with the updated FormResponses.\n\n```javascript\n// For a multiple choice question with options: \"Always true\", \"Sometimes true\",\n// and \"Never\", award half credit for responses that answered \"Sometimes true\".\nconst formResponses = FormApp.getActiveForm().getResponses();\n// Go through each form response\nfor (let i = 0; i \u003c formResponses.length; i++) {\n const response = formResponses[i];\n const items = FormApp.getActiveForm().getItems();\n // Assume it's the first item\n const item = items[0];\n const itemResponse = response.getGradableResponseForItem(item);\n // Give half credit for \"Sometimes true\".\n if (itemResponse != null && itemResponse.getResponse() === 'Sometimes true') {\n const points = item.asMultipleChoiceItem().getPoints();\n itemResponse.setScore(points * 0.5);\n // This saves the grade, but does not submit to Forms yet.\n response.withItemGrade(itemResponse);\n }\n}\n// Grades are actually submitted to Forms here.\nFormApp.getActiveForm().submitGrades(formResponses);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|-------------|\n| `score` | `Object` | |\n\n#### Return\n\n\n[ItemResponse](#) --- a `Item``Response` for chaining\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/forms.currentonly`\n- `https://www.googleapis.com/auth/forms`"]]