In Google Spreadsheet I am having the following issue:

I am using Session.getActiveUser().getUserLoginId() to fetch the current user's email id but other than creator of the spreadsheet it is returning empty string. I have also used getEffectiveUser() but no help.

I have even deployed this to "User accessing the web app" but still it's not working.

How can I fix this?


Short answer

getUserLoginID is deprecated. Instead use getMail.


From https://developers.google.com/apps-script/reference/base/user


Deprecated. As of June 24, 2013, replaced by getEmail()


Gets the user's email address, if available. If security policies do not allow access to the user's email address, this method returns a blank string. The circumstances in which the email address is available vary: for example, the user's email address is not available in any context that allows a script to run without that user's authorization, like a simple onOpen(e) or onEdit(e) trigger, a custom function in Google Sheets, or a web app deployed to "execute as me" (that is, authorized by the developer instead of the user). However, these restrictions generally do not apply if the developer and the user belong to the same Google Apps for Business domain.

 // Log the email address of the person running the script.

Wim den Herder posted a workaround based on the observation that a script cannot remove the current user from the list of editors of a protected range. They key part is as follows:

var protection = SpreadsheetApp.getActive().getRange("A1").protect();
var editors = protection.getEditors();

The first line protects cell A1. The second line attempts to remove all editors of a protected range. Any editors that are left are the spreadsheet owner and the current user. The protection is then removed altogether.


It's a late answer, but I posted it because I had the same problem, and the folowing unswer solved it for me :

To get the email address of the curent user you can use this function and it will return the email address saved in a variable :

function OnOpen(){
   var emailName = Session.getActiveUser().getEmail();
   var optionsHtml = emailName.toString().split(",");

   return optionsHtml;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.