2

this is my first Stackoverflow Questions, so I'm trying to do my best to be clear and structured here but please forgive me for beginner mistakes :)

So I'm having a little issue with the Script Editor of Google, basically I'm calling the Session.getActiveUser().getEmail() as well as the Session.getEffectiveUser().getEmail() Function yet none of them is returning a value.

Here's the full Code I'm using:

function onEdit(e){
    var email = Session.getActiveUser().getEmail();
    var range = e.range;
    range.setNote('Last modified: ' + new Date() + "User is " + Session.getEffectiveUser().getEmail() + "; " + Session.getActiveUser().getEmail());
}

Yet the Output I'm getting is always the same: Output in the Sheet

The weird thing is, that this occured a few days ago, before that the same functions worked fine.

Has someone ever experienced something like this? Is there a workaround to get the Mail-Adress or the User-Name in the Script-Editor?

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Is this a copy of a sheet is was working on previously? – James D Jan 10 '18 at 13:31
  • Not quite, as it was originally implemented in a bigger Project. But it's basically the same function-call and the same issue. – Bruce McGivern Jan 10 '18 at 13:48
  • So you have authorized the script in the new document? – James D Jan 10 '18 at 14:07
  • To be honest, I think I did, but I'm not sure. I've added these oauthScopes Values in the appscript.json: [oauthScopes](https://image.ibb.co/ctx796/auth.png) – Bruce McGivern Jan 11 '18 at 08:34
  • Update: I did authorize the Script but now I'm only getting the Console.log "Google Apps Script: We're sorry, a server error occurred. Please wait a bit and try again" Trying later does not seem to work, as I'm getting this since yesterday :) I do work with a workaround now nonetheless, but I'm still curious why it's not giving me the Mail-Adress anymore. – Bruce McGivern Jan 12 '18 at 21:27

1 Answers1

2

[In case you find yourself here] From the documentation:

...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...

This explains the behaviour the OP was facing...