onEdit trigger doesn't catch current user

前端 未结 1 1872
一生所求
一生所求 2020-12-20 02:05

I\'m trying to build a simple log for sheets that makes use of cell notes. Somehow i can\'t include the email of the user who triggers the onEdit-event.

相关标签:
1条回答
  • 2020-12-20 02:29

    Here's what Google documentation says about the Session class

    The Session class provides access to session information, such as the user's email address (in some circumstances) and language setting.

    In regards to 'getActiveUser()' method, it states

    If security policies do not allow access to the user's identity, User.getEmail() 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 G Suite domain.

    Because you use the simple trigger - onEdit() - the code will not execute unless explicitly authorized by the user. For installable triggers, that would mean executing the function manually from the script editor.

    You can publish the project as a sheets add-on. In this case, users will be asked to grant permissions declared in the add-on manifest.

    More info https://developers.google.com/apps-script/reference/base/session

    0 讨论(0)
提交回复
热议问题