Reputation: 313
Is there any way to have an onEdit function that fetches the editors name and writes it to B2 whenever A2 is changed?
https://docs.google.com/spreadsheets/d/1hYp2KAZSlRN2HNUWvyHAkc35mJtDPBSVipl4PtrSIJw/edit?usp=sharing
(e.g, the name of my google account is "Thomas G.", so this should be written to B2.) Possible?
Upvotes: 0
Views: 5037
Reputation: 3094
IMPORTANT CAVEAT: the code below will generally work only if the owner/publisher of the script and the user accessing the sheet belong to the same Google Apps domain. It will NOT work for non-apps users.
You can do this with the following onEdit() method in your sheet:
function onEdit(e) {
var editedRange = e.range;
if ( editedRange.getColumn()==1 ) { // if column A was edited
var u = Session.getActiveUser().getEmail();
editedRange.offset(0, 1).setValue(u); // write user's email to corresponding row in column B
}
};
Note: this will require users to authorize the script's access to their data on Google (to know the user's email).
Upvotes: 1