Here is my code:
var spreadsheet = SpreadsheetApp.getActive() ;
var sheet1 = spreadsheet.getSheetByName('ANULAR') ;
var sheet2 = spreadsheet.getSheetByName('PQ') ;
var todos = sheet1.getRange("D7").getValue();
var sqlData = sheet1.getRange("P4").getValue();
var cant = sheet1.getRange("R4").getValue();
var idpnqsAnular=sheet1.getRange("T6:T20").getValues();
var idpnqs= sheet2.getRange("A:A").getValues();
if (todos==true){
for (var i=0;i< idpnqs.length;i++){
for (var j=0;j<3;j++){
var a1=idpnqsAnular[j];//just for control on debugging
var a2=idpnqs[i];//just for control on debugging
var isIt=idpnqsAnular[j]==idpnqs[i];//just for control on debugging
if(isIt){
sheet2.getRange(i+1,6).setValue("CANCELADA");
}
}
}
}
}
The basic idea is: I have a list of codes in var idpnqsAnular
that I wanna delete in sheet2
when found.
That's why I iterate over idpnqs, and inside that for loop I iterate again over my list of codes. When the value on the ouside loop is equal to the value on the inside loop, in column 6 the value is changed to "CANCELADA" (cancelled in spanish). Problem is, the code never evaluates the values as equal, even when they are.
Here some captures from the debugging:
Even when a1
and a2
(variables created only for this detail on debugging) are exactly the same, the variable that compares them (isIt
) evaluates as false
.
Please, if you find the error, enlight my stupidity.
Thanks in advance