When using ScriptDb from within a WebApp that can be accessed by anyone and runs as the accessing user together with Triggers from within that WebApp it seems as if the user can not be correctly determined.
- Google Apps Script as
WebAppforAnyonerunningas the accessing user ScriptApp.newTrigger("myfunc").timeBased().everyMinutes(1).create();
Where function myfunc is:
var q = {
user: Session.getActiveUser().getEmail()
};
result = db.query(q).sortBy('when', db.ASCENDING);
result seems to be empty when myfunc is being accessed from the trigger.
Shouldn’t the active user within the trigger be the one that installed it? E.g. the user accessing the WebApp when first giving the authorization?
The Session.getEffectiveUser method returns the correct user email, as expected. Since when the script is running from a trigger, there’s no one “active” using it. The “effective” user though is always set, as it is the account which the script is running “under”. Here is a sample web application which emails an expected email address in the subject and body.