Generate automatic value and data when there are some value in a column in Google Sheets with GAS

In my spreadsheet I would generate automatically, when in col B there are these values:

  • yellow
  • green
  • black
  • brown

In col F the value "SI" and in col J the timestamp of the operation in col B.

https://docs.google.com/spreadsheets/d/1_oPC01vUjLYlCikyuk35bERa2Bughm_xDJSaim-wD58/edit#gid=0


Using onEdit to set value of column10 based on edit and value of B and value of F

 function onEdit(e) {
  //Logger.log(JSON.stringify(e));
  //e.source.toast('Entry')
  const sh = e.range.getSheet();
  if(sh.getName() == "Sheet1" && e.range.columnStart == 2 ) {
    //e.source.toast('Flag1')
    const cA = ['yellow','green','black','brown'];
    if(~cA.indexOf(e.value) && e.range.offset(0,4).getValue() == "SI") {
      //e.source.toast('Flag2')
      let ts = Utilities.formatDate(new Date(), Session.getScriptTimeZone(),"dd/MM/yyyy")
      sh.getRange(e.range.rowStart,10).setValue(ts);
    }
  }  
}