Home > Blockchain >  Vlookup not reflecting proper values on Apps script
Vlookup not reflecting proper values on Apps script

Time:08-31

I've made the following script to look for an specific word in a column in apps script:

function findCompliant() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheetByName('Sheet23');
  var rg = sh.getRange(2,1,sh.getLastRow() - 1,1);
  var v = rg.getValues();
  var searchTerm = "true";  
  const result = v.map(row => row[0].toString().toLowerCase().indexOf(searchTerm) > 1 ? ["It is true"]: ["it is false"])
  sh.getRange(2,3,result.length,1).setValues(result);
}

But when I try to lookup the "true" value in the column it all show up as "it is false", which it's incorrect as the data looks like this (it is a slice of the column that I'm looking for there's a total of 16 columns before my lookup column):

compliant
TRUE
FALSE
FALSE
TRUE
TRUE

I don't know what the code is doing as when I console log the getValues array it's getting me all the information however at the time of inserting the new column all the values are showing as everything is false, what can be causing the issue in here?

EDIT the results are coming like these:

enter image description here

CodePudding user response:

Try it like this:

This is working I believe

function findCompliant() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheetByName('Sheet0');//changed sheet name
  var rg = sh.getRange(2,17,sh.getLastRow() - 1,1);
  var v = rg.getValues();
  var searchTerm = "true";  
  const result = v.map(row => row[0].toString().toLowerCase().indexOf(searchTerm) > -1 ? ["It is true"]: ["it is false"]);//perhap you wish to say greater than -1
  sh.getRange(2,18,result.length,1).setValues(result);//changed column
}

perhaps you wish to say greater than minus one

Here's 17 and 18 of my sheet zero.

COL17 COL18
1true It is true
12true It is true
1TRUE It is true
12TRUE It is true
TRUE It is true
FALSE it is false
  • Related