0

I have some difficulty searching and creating a script. What I am trying to achieve is getting the user's email/name when they edited a cell in my spreadsheet. I tried getactiveuser but its not showing anything. I read that some ask to use geteffectiveuser but all I get is still my username back and not the other editor.

Here is my script so far:

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "TEST" ) { //checks that we're on the correct sheet
    var r = s.getActiveCell();
    var email = Session.getActiveUser().getEmail();
    if( r.getColumn() == 4 ) { //checks the column for HUB side
      var nextCell = r.offset(0, 1);
      if( nextCell.getValue() === '' ) //is empty?
        nextCell.setValue(email());
    }
  }
}

Logger.log(Session.getActiveUser().getEmail());

As of the above, nothing is showing up.

dbc
  • 104,963
  • 20
  • 228
  • 340
Renzo
  • 1
  • 2
  • https://developers.google.com/apps-script/reference/base/user. I think you need `getActiveUser().getEmail()` – Kin Siang Oct 03 '21 at 06:55
  • function onEdit() { var s = SpreadsheetApp.getActiveSheet(); if( s.getName() == "TEST" ) { //checks that we're on the correct sheet var r = s.getActiveCell(); var email = Session.getActiveUser().getEmail(); if( r.getColumn() == 4 ) { //checks the column var nextCell = r.offset(0, 1); if( nextCell.getValue() === '' ) //is empty? nextCell.setValue(email()); } } } Logger.log(Session.getActiveUser().getEmail()); Yes sir, this is my script but nothing is showing up. is there any workaround to this? – Renzo Oct 03 '21 at 13:52
  • You may post the code in your question panel, so that others can see what is the problem. – Kin Siang Oct 04 '21 at 00:04
  • Done and updated sir – Renzo Oct 04 '21 at 04:35

1 Answers1

0

You may perform a test on the following code, it work for me :)

function onEdit(e) {
  var s = e.source.getActiveSheet();
  if( s.getName() == "TEST" ) { //checks that we're on the correct sheet
    var r = e.range;
    if( r.getColumn() == 4 ) { //checks the column for HUB side
      var nextCell = r.offset(0, 1);
      if( nextCell.getValue() === '' ) //is empty?
        nextCell.setValue(Session.getActiveUser().getEmail());
    }
    
  }
}
Kin Siang
  • 2,644
  • 2
  • 4
  • 8
  • Hi its working for me the owner but its not working for other users. – Renzo Oct 05 '21 at 09:02
  • Try this and see? https://stackoverflow.com/questions/43848448/google-apps-script-get-users-email-address. I cannot test it alone `var email = Session.getEffectiveUser().getEmail()` – Kin Siang Oct 05 '21 at 10:38
  • The `Onedit(e)` cannot return email address other than the developer himself. https://stackoverflow.com/questions/60356262/how-can-i-get-email-of-the-last-user-who-modified-each-cell – Kin Siang Oct 05 '21 at 23:00