samedi 4 septembre 2021

Google sheets - colorize cells based on editor

I try to make a script for google sheets, to see what the editors modify. This is my script, but i have a problem.

function onEdit() {  
  var sheet = SpreadsheetApp.getActiveSheet();
  var email = Session.getActiveUser().getEmail();
  Logger.log(email);
  var User1 = email.indexOf("user1@email.com");
  var User2 = email.indexOf("user2@email.com");
  Logger.log(User1);
  Logger.log(User2);
  if (User1 = -1.0){
    sheet.getActiveCell().setBackground('#f4cccc')}
  if (User2 = -1.0){
    sheet.getActiveCell().setBackground('#c9daf8')}
}

Log looks correct:

11:42:08 AM Notice  Execution started
11:42:10 AM Info    user1@email.com
11:42:10 AM Info    0.0
11:42:10 AM Info    -1.0
11:42:09 AM Notice  Execution completed

But User1 & 2 got the same color(c9daf8). So i missed something.

Thanks for ur time and help!

Aucun commentaire:

Enregistrer un commentaire