Class FormResponse

  • 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 usinggetItemResponses(), or specifically retrieve gradable item responses usinggetGradableItemResponses().

  • Individual item responses can be retrieved usinggetResponseForItem(item) orgetGradableResponseForItem(item).

  • Methods likegetEditResponseUrl() 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 thesubmit() method and updated with item grades usingwithItemGrade(gradedResponse).

FormResponse

A response to the form as a whole. AFormResponse can be used in three ways: to accessthe answers submitted by a respondent (seegetItemResponses()), to programmaticallysubmit a response to the form (seewithItemResponse(response) andsubmit()), and to generate a URL for the form which pre-fills fields using the providedanswers.FormResponses 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

MethodReturn typeBrief description
getEditResponseUrl()StringGenerates a URL that can be used to edit a response that has already been submitted.
getGradableItemResponses()ItemResponse[]Gets all item responses contained in a form response, in the same order that the items appearin the form.
getGradableResponseForItem(item)ItemResponseGets the item response contained in a form response for a given item.
getId()String|nullGets the ID of the form response.
getItemResponses()ItemResponse[]Gets all item responses contained in a form response, in the same order that the items appearin the form.
getRespondentEmail()StringGets the email address of the person who submitted a response, if theForm.setCollectEmail(collect) setting is enabled.
getResponseForItem(item)ItemResponseGets the item response contained in this form response for a given item.
getTimestamp()DateGets the timestamp for a form response submission.
submit()FormResponseSubmits the response.
toPrefilledUrl()StringGenerates a URL for the form in which the answers are pre-filled based on the answers in thisform response.
withItemGrade(gradedResponse)FormResponseAdds the given item response's grades to a form response.
withItemResponse(response)FormResponseAdds 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 theForm.setRequireLogin(requireLogin) setting is enabled. If theForm.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.currentonly
  • https://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 togetItemResponses(), but to allow for gradinga missing answer, it still returns anItemResponse 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

ItemResponse[] — 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.currentonly
  • https://www.googleapis.com/auth/forms

getGradableResponseForItem(item)

Gets the item response contained in a form response for a given item. This method workssimilarly togetResponseForItem(item), but to allow for grading a missing answer, it stillreturns anItemResponse 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

NameTypeDescription
itemItem

Return

ItemResponse — 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.currentonly
  • https://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 givenTextItem,DateItem,TimeItem, orParagraphTextItem, theItemResponsereturned 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

ItemResponse[] — 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.currentonly
  • https://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.currentonly
  • https://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

NameTypeDescription
itemItem

Return

ItemResponse — 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.currentonly
  • https://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

FormResponse — 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.currentonly
  • https://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.currentonly
  • https://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

NameTypeDescription
gradedResponseItemResponse

Return

FormResponse — thisFormResponse, 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

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

NameTypeDescription
responseItemResponse

Return

FormResponse — ThisFormResponse, 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.