I am trying to create a google sheets custom menu based on the user email. Code is as follows:
var AllowedReportRecipients = ["u1@gmail.com", "u2@gmail.com", "u3@gmail.com"];
var ReportRecipient = null;
function onOpen()
{
var ui = SpreadsheetApp.getUi();
var menu = ui.createMenu('Custom');
menu.addItem('Edit', 'editHtm')
.addItem('History', 'historyHtm');
var usr = Session.getActiveUser().getEmail();
var isReportee = false;
for (var i=0;i<AllowedReportRecipients.length; i++)
if (AllowedReportRecipients[i] == usr)
{
ReportRecipient = usr;
isReportee = true;
}
if (isReportee)
menu.addItem('Request abc', 'sendABC');
menu.addToUi();
}
This is an unpublished sheet script. As others have reported the call to getActiveUser().getEmail() returns blank when the sheet is opened by the non-owner of the sheet. However, a call to getActiveUser().getEmail() executed at a later time correctly returns the logged in user email. For example, when called in historyHtm in response to the "History" menu item click it works. Why the difference? How do I properly load my menus?