Class ItemResponse

Item Response

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

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

Methods

Method Return type Brief description
Object Gets the feedback that was given for the respondent's submitted answer.
Item Gets the question item that this response answers.
Object Gets the answer that the respondent submitted.
Object Gets the score for the respondent's submitted answer.
Item Response Sets the feedback that should be displayed for the respondent's submitted answer.
Item Response Sets the score for the respondent's submitted answer.

Detailed documentation

get Feedback()

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

Return

Object — a Quiz Feedback for the question item

Authorization

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

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

get Item()

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 following scopes :

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

get Response()

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

For Checkbox Item questions, this returns a String[] array containing the responder's choices. The order of the strings in the array may vary.

For Grid Item questions, this returns a String[] array in which the answer at index n corresponds to the question at row n + 1 in the grid. If a respondent did not answer a question in the grid, that answer is returned as '' .

For Checkbox Grid Item questions, this returns a String[][] array in which the answers at row index n corresponds to the question at row n + 1 in the checkbox grid. If a respondent did not answer a question in the grid, that answer is returned as '' .

Return

Object — a String or String[] or String[][] of answers to the question item

Authorization

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

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

get Score()

Gets the score for the respondent's submitted answer.

Return

Object — a Double representing the score for the question item

Authorization

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

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

set Feedback(feedback)

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

This method does not actually save the feedback in Forms until Form.submitGrades(responses) is called with the updated FormResponses. See set Score() for an example.

Parameters

Name Type Description
feedback
Object

Return

Item Response — a Item Response for chaining

Authorization

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

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

set Score(score)

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

This method does not actually save the score in Forms until Form.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". 
 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 
 ); 

Parameters

Name Type Description
score
Object

Return

Item Response — a Item Response for chaining

Authorization

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

  • https://www.googleapis.com/auth/forms.currentonly
  • https://www.googleapis.com/auth/forms
Design a Mobile Site
View Site in Mobile | Classic
Share by: