0

This code works but it only works when I'm logged in as the owner of the sheet. If I login as a user (confirmed to be an editor) the values come back blank. NOTE: I found this but I'm not using Teams. This is just a sheet in a shared folder.

I found this that may explain it. But then, it seems pointless to use these functions if they only work for the user that wrote the script. Is there some set of permissions I need to add to the script in order to see the info for other users?

/**
* Creates a Date Stamp if a column is edited.
*/

//CORE VARIABLES
// Location of target cells to be updated
var USERCOL = 5;
var DATECOL = 6;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,1];
// Sheet you are working on
var SHEETNAME = 'Sheet1'

function onEdit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var aUser = Session.getActiveUser();
  var eUser = Session.getEffectiveUser();
  var sheet = ss.getActiveSheet();
  ss.toast('effective = ' + eUser + "\n" + 'active = ' + aUser + "\n", "info",-1);

  //checks that we're on the correct sheet.
  if( sheet.getSheetName() == SHEETNAME ) { 
    var selectedCell = ss.getActiveCell();
    //checks the column to ensure it is on the one we want to cause the date to appear.
    var col = selectedCell.getColumn();
    if( col >= 0 && col < 4) { 
      var sourceCell = selectedCell.offset(0,USERCOL - col);
      sourceCell.setValue(aUser);
      var dateTimeCell = selectedCell.offset(0,DATECOL - col);
      dateTimeCell.setValue(new Date());
    }
  }
}
player0
  • 124,011
  • 12
  • 67
  • 124
AdvApp
  • 1,094
  • 1
  • 14
  • 27

0 Answers0