I'm attempting to pull the ActiveUser and Email Address of the person making the change to the Google Sheet and thought it would be possible using the following, but all I can get is the timestamp. If I change "var obj2 = (Session.getActiveUser().getEmail()); to literally anything else, it pulls the new data so I feel like the rest of my script is fine but can't figure out why it never pulls a username or address...
Any thoughts as to what I'm doing wrong? I heard that possibly google does not allow this information to be pulled via onEdit anymore? If that's the case is there another way? If it can't be done automatically I'd settle for a way to add a popup where a person could enter their name and that would be added to the end of the timestamp but I haven't dug into popups yet.
DOESN'T WORK
function onEdit(e) { var r = e.range; var ss = r.getSheet(); // Prepare an object for searching sheet name. var obj = {'SHEET1': "D", 'SHEET2': "G"}; var obj2 = (Session.getActiveUser().getEmail()); // Using the object, check the sheet and put or clear the range. if (r.getColumn() == 1 && obj[ss.getSheetName()]) { var celladdress = obj[ss.getName()] + r.getRowIndex(); if (r.isChecked()) { ss.getRange(celladdress).setValue(new Date()).setNumberFormat(("MM/DD/YYYY hh:mm:ss") + " " + obj2); } else { ss.getRange(celladdress).clearContent(); } } }
DOES WORK (spits out Timestamp with a space and the word TEST at the end. Test is where I'd expect the username/email in the first example that doesn't currently work)
function onEdit(e) { var r = e.range; var ss = r.getSheet(); // Prepare an object for searching sheet name. var obj = {'SHEET1': "D", 'SHEET2': "G"}; var obj2 = ("TEST"); // Using the object, check the sheet and put or clear the range. if (r.getColumn() == 1 && obj[ss.getSheetName()]) { var celladdress = obj[ss.getName()] + r.getRowIndex(); if (r.isChecked()) { ss.getRange(celladdress).setValue(new Date()).setNumberFormat(("MM/DD/YYYY hh:mm:ss") + " " + obj2); } else { ss.getRange(celladdress).clearContent(); } } }
https://stackoverflow.com/questions/65784589/apps-script-onedit-combine-timestamp-and-username-email-address-not-working January 19, 2021 at 10:06AM
没有评论:
发表评论