// Purpose: to notice whenever anyone tries to add, delete or hide rows and columns
// In most cases I want to prevent others from doing it, but let me do it
function myFunction(e) { // catch any onChange events, e is the event object
if (typeof e != "object") Logger.log('Ooopps - no error object passed to the function');
let r = e.range;
if(typeof r != "undefined") { // as long as we have range data to test
if (AND(OR(e.changeType == INSERT_ROW, e.changeType == REMOVE_ROW), r.row < 12)) {
testAuth(e); // only I can do these things to the top 11 rows
} else if (OR(e.changeType == INSERT_COLUMN, e.changeType == REMOVE_COLUMN)) {
testAuth(e); // only I can do these things to any of the columns
} else if (e.changeType == OTHER) {
// figure out how to determine what OTHER change was made and if it is OK
} else {
// any other changes such as EDIT, FORMAT or GRIDs are OK, nothing to do
}
}
}
function testAuth(e) {
if (e.user.getEmail().toUpperCase() == 'MY_EMAIL_ADDRESS') {
Logger.log('Glen changed something - OK');
} else {
// user did one of the bad things and it wasn't me doing it so prevent it
Logger.log('Something changed but not by Glen - prevent it!');
}
}