Class ItemResponse

  • ItemResponse represents a response to a single question item within a form.

  • Item responses can be accessed from a FormResponse and created from an Item that asks for a response.

  • Methods are available to get and set feedback, the associated item, the respondent's answer, and the score for an item response.

  • The getResponse() method can return different types of data depending on the type of question item.

  • Setting feedback or score does not save the changes until Form.submitGrades() is called.

ItemResponse

A response to one question item within a form. Item responses can be accessed fromFormResponse and created from anyItem that asks the respondent to answer a question.

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

Methods

MethodReturn typeBrief description
getFeedback()ObjectGets the feedback that was given for the respondent's submitted answer.
getItem()ItemGets the question item that this response answers.
getResponse()ObjectGets the answer that the respondent submitted.
getScore()ObjectGets the score for the respondent's submitted answer.
setFeedback(feedback)ItemResponseSets the feedback that should be displayed for the respondent's submitted answer.
setScore(score)ItemResponseSets the score for the respondent's submitted answer.

Detailed documentation

getFeedback()

Gets the feedback that was given for the respondent's submitted answer.

Return

Object — aQuizFeedback for the question item

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

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

getItem()

Gets the question item that this response answers.

Return

Item — the question item that this response answers

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

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

getResponse()

Gets the answer that the respondent submitted. For most types of question items, this returns aString.

ForCheckboxItem questions, this returns aString[] array containing theresponder's choices. The order of the strings in the array may vary.

ForGridItem questions, this returns aString[] array in which the answer atindexn corresponds to the question at rown + 1 in the grid. If a respondentdid not answer a question in the grid, that answer is returned as''.

ForCheckboxGridItem questions, this returns aString[][] array in which theanswers at row indexn corresponds to the question at rown + 1 in the checkboxgrid. If a respondent did not answer a question in the grid, that answer is returned as''.

Return

Object — aString orString[] orString[][] of answers to the question item

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

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

getScore()

Gets the score for the respondent's submitted answer.

Return

Object — aDouble representing the score for the question item

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

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

setFeedback(feedback)

Sets the feedback that should be displayed for the respondent's submitted answer.

This method does not actually save the feedback in Forms untilForm.submitGrades(responses) is called with the updated FormResponses. SeesetScore() for an example.

Parameters

NameTypeDescription
feedbackObject

Return

ItemResponse — aItemResponse for chaining

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

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

setScore(score)

Sets the score for the respondent's submitted answer. A null value will clear the existingscore.

This method does not actually save the score in Forms untilForm.submitGrades(responses) is called with the updated FormResponses.

// For a multiple choice question with options: "Always true", "Sometimes true",// and "Never", award half credit for responses that answered "Sometimes true".constformResponses=FormApp.getActiveForm().getResponses();// Go through each form responsefor(leti=0;i <formResponses.length;i++){constresponse=formResponses[i];constitems=FormApp.getActiveForm().getItems();// Assume it's the first itemconstitem=items[0];constitemResponse=response.getGradableResponseForItem(item);// Give half credit for "Sometimes true".if(itemResponse!=null &&itemResponse.getResponse()==='Sometimes true'){constpoints=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);

Parameters

NameTypeDescription
scoreObject

Return

ItemResponse — aItemResponse for chaining

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

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

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.