Acquire the email address of responder when a form response is submitted

1,574 views
Skip to first unread message

james cui

unread,
Dec 21, 2021, 10:58:51 PM12/21/21
to google-apps-sc...@googlegroups.com
Hey guys,

I have the requirement to get the email address of the responder when a form is submitted, but it seems that is not possible from a form trigger. Are there any workarounds used by folks in the community? 




Thanks in advance!

Alan Wells

unread,
Dec 22, 2021, 11:08:32 AM12/22/21
to Google Apps Script Community
The user filling out the Form needs to be logged into their Google account to get their email. And there's a setting in the Form 
that you need to turn ON. Go into the Form settings - In the "Defaults" section you will see:  Collect email addresses by default.
In your function that gets triggered by the Form submission you need to have a variable name for the event object. People often use the letter "e" for the event object.
From the event object you can get the ID number of the response that the current run instance is handling.

function my_Form_Submit_Fnk(e) {

  var the_Response_ID = e.response.getId();
  var the_Form = FormApp.getActiveForm();
  var the_Response =  the_Form.getResponse( the_Response_ID );//Get the response that was just submitted

  var theCollected_Email =  the_Response_ID.getRespondentEmail();
  theCollected_Email =  theCollected_Email  ?  theCollected_Email : false;

james cui

unread,
Dec 22, 2021, 1:04:46 PM12/22/21
to google-apps-sc...@googlegroups.com
Thanks Alan for the explanation plus a sample code!

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/fb5c0607-e347-4ef0-b72b-a3b3e9600eebn%40googlegroups.com.

Alan Wells

unread,
Dec 22, 2021, 1:17:35 PM12/22/21
to Google Apps Script Community
Thanks for the feedback. There is a mistake in one line. Should be:
var theCollected_Email = the_Response.getRespondentEmail();

james cui

unread,
Dec 22, 2021, 1:50:27 PM12/22/21
to google-apps-sc...@googlegroups.com
I tried the method, but I found that changing the settings in google form actually simply added a "Email" form question to the form.
This works for sure, but are there ways to get email without "increasing user's burden"? I mean some way to get the email explicitly? 

Alan Wells

unread,
Dec 22, 2021, 2:59:37 PM12/22/21
to Google Apps Script Community
A Google Form can not automatically collect email addresses except under certain conditions. A Google Form can NOT collect a non-Google email. Also, a Google Form can only automatically collect a Google email from users within the same domain. That means that only Google emails from within the same business, or organization have this capability available.

Jonathan Butler

unread,
Dec 22, 2021, 4:19:36 PM12/22/21
to google-apps-sc...@googlegroups.com
Hi,

If you have the collect email addresses by default, enabling the setting will automatically create an email field. 

image.png

When a user submits a form a onFormSubmit event is triggered. The response property yourArgumentName.response returns a form response object. This should have the getRespondentEmail function. Alternatively, whenever a form is attached to a sheet a row is added automatically. So once the trigger is received, you can get the latest row in the sheet with yourSheetName.getLastRow(). You can hard code the email column or do a lookup with the array indexOf function for the first row. Then you grab the value with sheet.getRange(lastRow,emailColumn).getValue()


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages