Google Apps Script

Class FormResponse

A response to the form as a whole. Form responses have three main uses: they contain the answers submitted by a respondent (see getItemResponses(), they can be used to programmatically respond to the form (see withItemResponse(response) and submit()), and they can be used as a template to create a URL for the form with pre-filled answers. Form responses can be created or accessed from a Form.

 // Open a form by ID and log the responses to each question.
 var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
 var formResponses = form.getResponses();
 for (var i = 0; i < formResponses.length; i++) {
   var formResponse = formResponses[i];
   var itemResponses = formResponse.getItemResponses();
   for (var j = 0; j < itemResponses.length; j++) {
     var itemResponse = 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, even if the Form.setAllowResponseEdits(enabled) setting is disabled.
getId()StringGets the ID of the form response.
getItemResponses()ItemResponse[]Gets all item responses contained in this form response, in the same order as the items appear in the form.
getRespondentEmail()StringGets the email address of the person who submitted this response, if the Form.setCollectEmail(collect) setting is enabled.
getResponseForItem(item)ItemResponseGets the item response contained in this form response for a given item.
getTimestamp()DateGets the timestamp at which this response was submitted.
submit()FormResponseSubmits the response.
toPrefilledUrl()StringGenerates a URL for the form in which the answers are pre-filled based on the answers in this form response.
withItemResponse(response)FormResponseAdds an item response to this form response.

Detailed documentation

getEditResponseUrl()

Generates a URL that can be used to edit a response that has already been submitted, even if the Form.setAllowResponseEdits(enabled) setting is disabled. Anyone who visits the link can edit the response, although they need an account with access to the form if the Form.setRequireLogin(requireLogin) setting is enabled. If the Form.setCollectEmail(collect) setting is enabled, the form records the email address of the user who edited the response instead of the email address of the original respondent.

For a form response that the script has created but not yet submitted, this method returns null.

Return

String — the URL to change a submitted response


getId()

Gets the ID of the form response. This method returns null if the form response has not been submitted.

Return

String — the ID of the form response, or null if the form response has not been submitted


getItemResponses()

Gets all item responses contained in this form response, in the same order as the items appear in the form. If form response does not contain a response for an item, that item response is excluded from the array.

Return

ItemResponse[] — an array of responses to every question item within the form for which the respondent provided an answer


getRespondentEmail()

Gets the email address of the person who submitted this response, if the Form.setCollectEmail(collect) setting is enabled.

For a form response that the script has created but not yet submitted, this method returns null.

Return

String — the email address of the person who submitted this response, if available, or null if the script created this response but has not yet submitted it


getResponseForItem(item)

Gets the item response contained in this form response for a given item.

Parameters

NameTypeDescription
itemItem

Return

ItemResponse — the response for a given item, or null if none exists


getTimestamp()

Gets the timestamp at which this response was submitted.

For a form response that the script has created but not yet submitted, this method returns null.

Return

Date — the timestamp at which this response was submitted, or null if the script created this response but has not yet submitted it


submit()

Submits the response. Throws a scripting exception if the response has already been submitted.

Return

FormResponse — a newly created response saved to the form's response store


toPrefilledUrl()

Generates a URL for the form in which the answers are pre-filled based on the answers in this form response.

Return

String — the URL for a form with pre-filled answers


withItemResponse(response)

Adds an item response to this form response. This method applies only to form responses that the script has created but not yet submitted; it cannot affect stored responses. If this method is called multiple times for the same item, only the last item response is retained.

Parameters

NameTypeDescription
responseItemResponse

Return

FormResponse — this FormResponse, for chaining

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.