jeudi 11 novembre 2021

google script array of check boxes comparison not working

True/False values from an array of check boxes it not being recognized properly.

// check boxes on every other cell on a sheet named Display in column J



var ckj_ar = ss.getRange('Display!J2:J32').getValues();   //array 

Input to the array above was checked with the alerts below (commented out now) and are getting populated correctly.

//  SpreadsheetApp.getUi().alert("check 0= " +ckj_ar[0]);  
//  SpreadsheetApp.getUi().alert("check 2= " +ckj_ar[2]);
//  SpreadsheetApp.getUi().alert("check 4= " +ckj_ar[4]);
//  SpreadsheetApp.getUi().alert("check 6= " +ckj_ar[6]);

The if statement below checks if the first value of the array is true or false if false "unchecked" it does not change anything and just copies data over. if true "checked" it looks up was is in the validation box and flips values displayed.

All that worked fine until I shortened the long handed code with an array. The first comparison here never equals false, even when checked so the else always runs.

Not sure why a variable worked here but not an array with the same value?

if(ckj_ar[0] == false){
    ss.getRange('Display!N2').setValue('=VLOOKUP(O2,teams!$A$1:$B$33,2,false)'); 
    ss.getRange('Display!O2').setValue('=F2'); 
   }
     else{
       var steam = ss.getRange('Display!F2').getValue();         // selected team
       var team1 = ss.getRange('Display!C2').getValue();         // first team
       var team2 = ss.getRange('Display!C3').getValue();         // second team
       if(steam == team1){
         ss.getRange('Display!O2').setValue(team2); 
         ss.getRange('Display!N2').setValue('=VLOOKUP(O2,teams!$A$1:$B$33,2,false)');
       }
       if(steam == team2){
         ss.getRange('Display!O2').setValue(team1); 
         ss.getRange('Display!N2').setValue('=VLOOKUP(O2,teams!$A$1:$B$33,2,false)');
       }
     }



Aucun commentaire:

Enregistrer un commentaire