In order to track the latest change on a specific line in a google sheet and adding user credentials to a specified column on that line with the function below works perfectly in a test sheet I created my own.
However, the exact same formula with parameters (sheet name / column numbers) adapted, it does not work any more in another sheet.
The only difference I can think of is, that in case 1 (test sheet) I am the owner of the document and in the latter I am not. Other Makro functions versions / extensions of the function below did make changes to the sheet though, so I am expecting it is not a write permissions issue.
What could be the issue here?
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var usercolumn = 1; // Change this to the column number you want to edit
var users = {
"User1@gmail.com": "User1",
"User2@gmail.com": "User2",
"User3@gmail.com": "User3"
}; // Change this to the mapping of user email addresses to values
if (sheet.getName() == "MySheetName" && e.range.getColumn() == 2 && users.hasOwnProperty(e.user.getEmail())) {
sheet.getRange(e.range.getRow(), usercolumn).setValue(users[e.user.getEmail()]);
}
}
Tried different variations of the function; sometimes it would delete the content of the specified cell, that I was expecting it to write "User1" ( ... ) for me.