0

I work on a Google Drive with other people and we have multiple google sheets. I defined a "OnEdit" function to get the name of the people editing a specific column in a sheet, so that I can send to discord the following message "User X has updated the sheet Y."

But I can't get the name of the current user (except me). I use the following script:

function getCurrentUserEmail() { var protection = SpreadsheetApp.getActive().getRange('A1').protect(); protection.removeEditors(protection.getEditors()); var editors = protection.getEditors(); if (editors.length === 2) { var owner = SpreadsheetApp.getActive().getOwner(); editors.splice(editors.indexOf(owner), 1); } var userEmail = editors[0]; protection.remove(); return userEmail;} 

I believe the user editing the script doesn't have the authority to execute "removeEditors"

The classic "Session.getActiveUser()" also doesn't work for anyone but me (it returns a blank)

It is starting to become frustrating; if it is a problem of access rights, what can I do?

2

1 Answer 1

-1

Your users would need to authorise the script for it to work - this is so that you can't collect user data without their permission.

You could maybe try to run an onOpen check to see if the user has already authorised your script, and if not, prompt them to execute a placeholder function.

You could log authorisation from users (eg. on a hidden sheet).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.