Search code examples
javascriptgoogle-apps-scriptgoogle-forms

Extract Respondent Email from Google Forms Responses using Google Apps Script


I'm using Google Apps Scripts to handle response data from a Google Form, and the form asks the users to prove a username at the start of the form. The usernames have been provided to them earlier. I'm now trying to match the given username to the email ID that was used to respond to the form (setLimitOneResponsePerUser() has been set to true, thus all users have to be signed in to respond), using values in a spreadsheet.

But I can't seem to get a value from Response.getRespondentEmail() (returns blank) unless I have Form.setCollectEmail() set to true, which I'm trying to avoid, as that means they'll have to manually enter the email ID's every time.

Is there a way to extract the email ID that was used to create a response?

NOTE: I cannot use the event object as the script does not run on a ResponseTrigger, rather it runs daily at a given time, and iterates through all the submitted responses for that form.


Solution

  • Answering my own question, in case others check this thread out.

    So it turns out there currently isn't a way to auto-collect email address using Google Scripts unless either:

    1. Form.setCollectEmail() is set to true, in which case the respondent has to manually enter in an email ID each time (and can be faked, because it won't be cross-checked with the actual account used to sign in)

    OR

    1. The script runs on a Form ResponseTrigger, in which case the associated email ID will be part of the Event object e. But this method cannot be used for analysing responses at a later stage.

    Unfortunate that this hasn't been implemented in Google Apps Script yet, but let's see what happens in the future.

    Hope this is helpful to anyone else who stumbles upon this thread.