Class FormResponse Stay organized with collections Save and categorize content based on your preferences.
Page Summary
A FormResponse object represents a response to a Google Form and can be used to access, submit, or generate pre-filled URLs for responses.
You can retrieve all item responses for a form response using
getItemResponses(), or specifically retrieve gradable item responses usinggetGradableItemResponses().Individual item responses can be retrieved using
getResponseForItem(item)orgetGradableResponseForItem(item).Methods like
getEditResponseUrl()andtoPrefilledUrl()allow for generating URLs to edit submitted responses or create pre-filled forms based on existing responses.Form responses can be programmatically submitted using the
submit()method and updated with item grades usingwithItemGrade(gradedResponse).
A response to the form as a whole. AForm can be used in three ways: to accessthe answers submitted by a respondent (seeget), to programmaticallysubmit a response to the form (seewith andsubmit()), and to generate a URL for the form which pre-fills fields using the providedanswers.Forms can be created or accessed from aForm.
// 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
| Method | Return type | Brief description |
|---|---|---|
get | String | Generates a URL that can be used to edit a response that has already been submitted. |
get | Item | Gets all item responses contained in a form response, in the same order that the items appearin the form. |
get | Item | Gets the item response contained in a form response for a given item. |
get | String|null | Gets the ID of the form response. |
get | Item | Gets all item responses contained in a form response, in the same order that the items appearin the form. |
get | String | Gets the email address of the person who submitted a response, if theForm.setCollectEmail(collect) setting is enabled. |
get | Item | Gets the item response contained in this form response for a given item. |
get | Date | Gets the timestamp for a form response submission. |
submit() | Form | Submits the response. |
to | String | Generates a URL for the form in which the answers are pre-filled based on the answers in thisform response. |
with | Form | Adds the given item response's grades to a form response. |
with | Form | Adds the given item response to a form response. |
Detailed documentation
getEditResponseUrl()
Generates a URL that can be used to edit a response that has already been submitted. If theForm.setAllowResponseEdits(enabled) setting is disabled, the link leads to a page thatexplains that editing form responses is disabled. Anyone who visits the link can edit theresponse, although they need an account with access to the form if the setting is enabled. If theForm.setRequireLogin(requireLogin)Form.setCollectEmail(collect)setting is enabled, the form records the email address of the user who edited the responseinstead of the email address of the original respondent.
For a form response that the script has created but not yet submitted, this method returnsnull.
// 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.constform=FormApp.openById('abc123456');// Gets the first form response.constformResponse=form.getResponses()[0];// Gets the edit URL for the first form response and logs it to the console.consteditUrl=formResponse.getEditResponseUrl();console.log(editUrl);
Return
String — The URL to change a submitted response.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/forms
getGradableItemResponses()
Gets all item responses contained in a form response, in the same order that the items appearin the form. This method works similarly toget, but to allow for gradinga missing answer, it still returns anItem if the correspondingItemcan be graded (that is, has a point value), even if there isn't an actual response. However, iftheItem isn't gradable, this method excludes that item from its returned array.
// 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.constform=FormApp.openById('abc123456');// Gets an array of the form's responses.constformResponses=form.getResponses();// Gets the item responses contained in each form response.for(constformResponseofformResponses){constgradableItemsResponses=formResponse.getGradableItemResponses();// Logs the title and score for each item response to the console.for(constgradableItemsResponseofgradableItemsResponses){console.log(`${gradableItemsResponse.getItem().getTitle()} score${gradableItemsResponse.getScore()}`);}}
Return
Item — An array of responses to every question item within the form for which the respondent could receive a score.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/forms
getGradableResponseForItem(item)
Gets the item response contained in a form response for a given item. This method workssimilarly toget, but to allow for grading a missing answer, it stillreturns anItem if the correspondingItem can be graded (that is, has apoint value), even if there isn't an actual response. However, if theItem isn'tgradable, this method returnsnull.
// 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.constform=FormApp.openById('abc123456');// Gets an array of the form's responses.constformResponses=form.getResponses();// Gets the item responses contained in a form response.for(constformResponseofformResponses){constformItemResponses=formResponse.getGradableItemResponses();// Logs the title and score for responses to the first item of the form.constitemResponse=formResponse.getGradableResponseForItem(formItemResponses[0].getItem(),);console.log(`${itemResponse.getItem().getTitle()} score${itemResponse.getScore()}`,);}
Parameters
| Name | Type | Description |
|---|---|---|
item | Item |
Return
Item — The response for a given item, ornull if none exists and the item is ungraded.
getId()
Gets the ID of the form response. This method returnsnull if the form response has notbeen submitted.
// 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.constform=FormApp.openById('abc123456');// Gets an array of the form's responses.constformResponses=form.getResponses();// Loops through the form responses and logs the ID for each form response to// the console.for(constformResponseofformResponses){console.log(`Response ID:${formResponse.getId()}`);}
Return
String|null — The ID of the form response, ornull if the form response has not been submitted.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/forms
getItemResponses()
Gets all item responses contained in a form response, in the same order that the items appearin the form. If the form response does not contain a response for a givenText,Date,Time, orParagraph, theItemreturned for that item will have an empty string as the response. If the form response omits aresponse for any other item type, this method excludes that item from its returned array.
// 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.constform=FormApp.openById('abc123456');// Gets the responses to the form.constformResponses=form.getResponses();// Iterates over the responses.for(constformResponseofformResponses){// Gets the item responses from each form response.constitemResponses=formResponse.getItemResponses();// Iterates over the item responses.for(constitemResponseofitemResponses){// Logs the items' questions and responses to the console.console.log(`Response to the question '${itemResponse.getItem().getTitle()}' was '${itemResponse.getResponse()}'`);}}
Return
Item — An array of responses to every question item within the form for which the respondent provided an answer.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/forms
getRespondentEmail()
Gets the email address of the person who submitted a response, if theForm.setCollectEmail(collect) setting is enabled.
For a form response that the script has created but not yet submitted, this method returnsnull.
// 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.constform=FormApp.openById('abc123456');// Gets an array of the form's responses.constformResponses=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(constformResponseofformResponses){console.log(`Respondent Email:${formResponse.getRespondentEmail()}`);}
Return
String — The email address of the person who submitted this response, if available, ornull if the script created this response but has not yet submitted it.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/forms
getResponseForItem(item)
Gets the item response contained in this form response for a given 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.constform=FormApp.openById('abc123456');// Gets the first item on the form.constitem=form.getItems()[0];// Gets an array of the form's responses.constformResponses=form.getResponses();// Loops through the responses and logs each response to the first item to the// console.for(constformResponseofformResponses){constitemResponse=formResponse.getResponseForItem(item);console.log(itemResponse.getResponse());}
Parameters
| Name | Type | Description |
|---|---|---|
item | Item |
Return
Item — The response for a given item, ornull if none exists.
getTimestamp()
Gets the timestamp for a form response submission.
For a form response that the script has created but not yet submitted, this method returnsnull.
// 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.constform=FormApp.openById('abc123456');// Gets an array of the form's responses.constformResponses=form.getResponses();// Loops through the responses and logs the timestamp of each response to the// console.for(constformResponseofformResponses){console.log(`Timestamp:${formResponse.getTimestamp()}`);}
Return
Date — The timestamp at which this response was submitted, ornull if the script created this response but has not yet submitted it.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/forms
submit()
Submits the response. Throws a scripting exception if the response has already been submitted.
// 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.constform=FormApp.openById('abc123456');// Creates an empty response for the form.constformResponse=form.createResponse();// Submits an empty response.formResponse.submit();
Return
Form — A newly created response saved to the form's response store.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/forms
toPrefilledUrl()
Generates a URL for the form in which the answers are pre-filled based on the answers in thisform 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.constform=FormApp.openById('abc123456');// Gets the first form response.constformResponse=form.getResponses()[0];// Generates and logs the URL of a pre-filled form response based on the answers// of the first form response.constprefilledUrl=formResponse.toPrefilledUrl();console.log(prefilledUrl);
Return
String — The URL for a form with pre-filled answers.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/forms
withItemGrade(gradedResponse)
Adds the given item response's grades to a form response. This method applies only to formresponses that have already been submitted, and only affects stored grades once they aresubmitted. This method also only updates the item response's grades; it does not affect theactual response (since the response has already been submitted). If this method is calledmultiple times for the same item, only the last grade is retained. If the ItemResponse containsno grades, this method removes grades for the item.
// Programmatically award partial credit for a given responseconstform=FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');constformResponses=form.getResponses();constformItems=form.getItems();for(constformResponseofformResponses){for(constitemofformItems){constpoints=item.asMultipleChoiceItem().getPoints();constitemResponse=formResponse.getGradableResponseForItem(item);Logger.log('Award half credit for answers containing the word "Kennedy"');constanswer=itemResponse.getResponse();if(answer?.includes('Kennedy')){itemResponse.setScore(points/2);formResponse.withItemGrade(itemResponse);}}}form.submitGrades(formResponses);
Parameters
| Name | Type | Description |
|---|---|---|
graded | Item |
Return
Form — thisForm, for chaining
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/forms
withItemResponse(response)
Adds the given item response to a form response. This method applies only to form responsesthat the script has created but not yet submitted; it cannot affect stored responses. If thismethod is called multiple times for the same item, only the last item response is retained.
// 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.constform=FormApp.openById('abc123456');// Creates a response for the form.constformResponse=form.createResponse();// Appends a checkbox item to the form.constitem=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.constresponse=item.createResponse(['Vanilla','Strawberry']);// Adds the item response to the form response.formResponse.withItemResponse(response);// Submits the form response.formResponse.submit();
Parameters
| Name | Type | Description |
|---|---|---|
response | Item |
Return
Form — ThisForm, for chaining.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://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.