Unable To Remove The Effective User From Editing Rights Of Protected Range Using Script - Google Sheets
In google sheets I'm trying to use a script to make a protected range. I'd like the script to make a protected range that ONLY the owner can edit, and no one else, however the scr
Solution 1:
removeEditors() does not allow the current user to be removed:
Removes the given array of users from the list of editors for the protected sheet or range. Note that if any of the users are members of a Google Group that has edit permission, or if all users in the domain have edit permission, those users will still be able to edit the protected area. Neither the owner of the spreadsheet nor the current user can be removed.
However, you can use an Installable Trigger created by the owner that will run your setProtections()
method as the user that created the Trigger [owner] - even if it is triggered by another user.
Example: Installable Trigger onEdit()
function installedOnEditTrigger (e) {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
//Checks if the sheet edit happened in the 7th column "G"if (e.range.getColumn() == 7) {
varrange = ss.getRange('G1:G10');
var protection = range.protect()
var editors = protection.getEditors();
//Removes all editors - owners can not be removed
protection.removeEditors(editors);
}
}
Post a Comment for "Unable To Remove The Effective User From Editing Rights Of Protected Range Using Script - Google Sheets"