0
votes

I have a Google Apps Script that is shared with another user (I own both users - one is my personal Gmail and one is my work account on Gsuite). The script scans threads in my inbox, and applies labels to the threads based on rules.

I set up time-based triggers from each user account to run the script.

The script calls Session.getActiveUser().getEmail() to identify which user is running it, and sets some parameters differently depending on the user.

Logging shows that, for either user, the script errors about half the time, intermittently, saying "The script does not have permission to get the active user's identity." (Clearly it DOES have permission, for each user, or else it would fail every time.)

To troubleshoot this, I stopped sharing the script between users. I made separate copies of the same code, in each user's account. Now the script is running fine for both users.

Can anyone confirm that this is a bug in Google's operating environment? That (I suspect) somehow the operating environment gets confused about which user is running the shared script?

(I did search this forum and can't find a description that explains it)

1
How is the function called? What name is it using? Note that if you registered an installed "on edit" trigger, that trigger activates for every users' edits, not just edits made by the user that installed the trigger. - tehhowch
var currentUser = Session.getActiveUser().getEmail(); - knwpsk
The trigger for each user is just a time-based trigger to run the function periodically. It's not an "on edit" trigger. The overall function is grabbing a handful of threads in my gmail inbox and applying labels to them. - knwpsk

1 Answers

0
votes

You should be using getEffectiveUser(), since there is not necessarily an active user when the time-based trigger triggers.

From the documentation (linked above):

If the script is running under an installable trigger, this returns the account of the user who created the trigger.