1

I have a Google Sheet that I would like to automatically stamp the username of the person who last made a change to a specific row. I currently have this code to work as I like to do the same function with the time:

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  var r = s.getActiveCell();
  if( r.getColumn() != 2 ) { //checks the column
    var row = r.getRow();
    var time = new Date();
    time = Utilities.formatDate(time, "GMT-07:00", "yyyy-MM-dd, hh:mm:ss");
    SpreadsheetApp.getActiveSheet().getRange('G' + row.toString()).setValue(time);
  };
 };

Assuming this is somewhat close to what I require for the username, I tried using this:

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  var r = s.getActiveCell();
  if( r.getColumn() != 2 ) { //checks the column
    var row = r.getRow();
    var time = new Date();
    time = Utilities.formatDate(time, "GMT-07:00", "yyyy-MM-dd, hh:mm:ss");
    SpreadsheetApp.getActiveSheet().getRange('H' + row.toString()).setValue(Session.getActiveUser);
  };
 };

But that spits out some weird command that is clearly broken.

How can I do this?

This is the sheet I am working on: https://docs.google.com/spreadsheets/d/1VifU8AJWuPn53-_JCQKbPTjHxKDArkyG0G7zt1wzmPg/edit?usp=sharing

08Dc91wk
  • 4,254
  • 8
  • 34
  • 67
Jimmy
  • 83
  • 1
  • 2
  • 4
  • http://stackoverflow.com/questions/34961832/can-i-automatically-record-in-a-google-sheet-column-the-timings-that-other-goo ... Is this similar to this question ? – user1790836 Jan 24 '16 at 06:59

1 Answers1

1

Is this what you are trying to do?

function onEdit(e) {
  var r = e.range;
  if( r.getColumn() != 2 ) { //checks the column
    var time = new Date();
    time = Utilities.formatDate(time, "GMT-07:00", "yyyy-MM-dd, hh:mm:ss");
    SpreadsheetApp.getActiveSheet().getRange(r.getRow(),8).setValue(Session.getActiveUser().getEmail());
  }
 }
Akshin Jalilov
  • 1,658
  • 1
  • 12
  • 12