get the email of the user that answered the google form

2,039 views
Skip to first unread message

Rocio López Dávila

unread,
Jun 15, 2021, 12:44:50 PM6/15/21
to Google Apps Script Community
Hi everybody,

I am developing a script in a google form, which when the user click on submit button, a customized scripts is executed.

In this script i want to capture the email of the person who is sending the google form but I don't get it.

I am using google accounts that belongs to a g suite education organization.

I have disabled the option "collect email", because i don't want that the user insert manually his address email, i want that the system take it automatically.

Here is the code that i have in the script that it is executed when the user click on submit button: (a trigger)

function onFormSubmit() {
    var eMail = Session.getActiveUser().getEmail();
    Logger.log(eMail);
}

I also tried this another implementation:

function onFormSubmit() {
     var formURL = FormApp.getActiveForm().getEditUrl();
     var form = FormApp.openByUrl(formURL);
     var formResponses = form.getResponses();
     var lastResponse = formResponses[formResponses.length-1];
     var eMail = lastResponse.getRespondentEmail() ;
     Logger.log(eMail);
}

Both of them are not working, they return an empty field.

I appreciate if someone could help me.

Thanks very much

Rocio

Bennett, Scott

unread,
Jun 15, 2021, 12:48:19 PM6/15/21
to google-apps-sc...@googlegroups.com
You want to enable the collect email.  Then they have to sign in to a google account to answer the form.  It will pull the email from their account.  
That is how it works in organizations.

--
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/3f2edf2a-2885-4e50-a119-86fbd255733fn%40googlegroups.com.


--
Scott Bennett


Rocio López Dávila

unread,
Jun 15, 2021, 12:57:59 PM6/15/21
to Google Apps Script Community
I don want to enable the collect email, because if i enable this option, an email field is showed, and the user has to insert manually his email address in this email field

Captura.JPG
The idea is that the user doesnt have to insert his email, instead of this, the system should collect it automatically.

Bennett, Scott

unread,
Jun 15, 2021, 1:03:32 PM6/15/21
to google-apps-sc...@googlegroups.com
Are they required to sign into a google account to answer the form?

Rocio López Dávila

unread,
Jun 15, 2021, 1:12:15 PM6/15/21
to Google Apps Script Community
yes, because i send them the form to their email.

After that,  they receive the url of the form through email and complete it.

kk.jpg

Bennett, Scott

unread,
Jun 15, 2021, 1:22:32 PM6/15/21
to google-apps-sc...@googlegroups.com
When I select this option.
image.png

It pulls the email straight from the account.  So there is no option for them to type it in.  It shows up as the second value after the timestamp.  


Bennett, Scott

unread,
Jun 15, 2021, 1:31:35 PM6/15/21
to google-apps-sc...@googlegroups.com
Also are you using an installable trigger?  

Rocio López Dávila

unread,
Jun 15, 2021, 1:34:28 PM6/15/21
to google-apps-sc...@googlegroups.com
yes, i just see right now which was the problem.
I had to enable two option: collect email and limit to the user of the organization.
I just tried the form, with the first option enable (collect the email) and therefore, the system make the user to write manually his email
But if I enable also the other option (limit to the user of the organization...), the system take automatically the email of the person who is completing the form.
solucion.JPG

Thanks very much!!!!

Bennett, Scott

unread,
Jun 15, 2021, 1:55:42 PM6/15/21
to google-apps-sc...@googlegroups.com
If you use an installable trigger you can save a lot of code
function onSubmit(e) {
  let resp = e.response
  let respEmail = resp.getRespondentEmail()
  Logger.log(respEmail); 
}

Rocio López Dávila

unread,
Jun 15, 2021, 2:04:46 PM6/15/21
to google-apps-sc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages