Question

I've been trying to get some custom validations and access checks done in spreadsheets, based on the groups the users belong to.

As far as I know, the following trigger bound to a container(a spreadsheet) should have the rights of the user accessing the spreadsheet:

function onEdit(event) {
    var groups = GroupsApp.getGroups();
    Logger.log(groups);
}

Still, it runs into an error: "Execution failed: You do not have permission to call getGroups". The same function called from a standalone script file(in theory the same access) will see the groups of the user.

My questions are:

  • Am I doing something wrong?
  • If not, is there a way to access the groups of a user from a spreadsheet event?

Probably not relevant, but using Windows 8 and Chrome 30.0.1599.101 m.

Was it helpful?

Solution

Zig Mandel's answer is correct as simple events like onEdit are unable to call methods that require authorization,however you were trying to get the user's group and that will be a problem since installable triggers run under the authority of the author of the script (in fact the person that set up the trigger which is usually the script author) which means not the user's group but yours...

So I'm afraid what you are trying to do won't be possible because in contradiction with the privacy rules in spreadsheet scripts.(read the doc that Zig refers to in his answer)

The only way to access the user's group information is using a direct function call in a menu or using a button that will ask for authorization., no automation in there ...

OTHER TIPS

If you were to read onEdit documentation it says that you cant call methods that require authentication. Install the trigger with a different name instead of using the simple trigger.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top