Session.getActiveUser().getEmail() returns no Value

六眼飞鱼酱① 提交于 2020-07-30 07:56:48

问题


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?

Thanks and best regards!


回答1:


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



来源:https://stackoverflow.com/questions/48183463/session-getactiveuser-getemail-returns-no-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!