Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

To filter data based on ID list found in other tab using App Script

I want to scrape data, but only filter data if Col13 from the data have the IDs listed in another tab. If I hardcode for 1 ID, I managed to do as below:

var sid = ss.getSheetByName('sid list').getRange('A2:A').getValues(); //capture list of IDs
        if(temp[13] == 243558369) {

        temp.push(counter)
        // console.log(temp)
        toPrint.push(temp)
        counter++
        }

This is the list of IDs to be captured var sid = ss.getSheetByName('sid list').getRange('A2:A').getValues(); //capture list of IDs

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To filter data based on a list of IDs from another tab, you can modify your code to loop through the list of IDs and check if the value of Col13 matches any of the IDs in the list. Here’s an example of how you can achieve this:

var sidList = ss.getSheetByName('sid list').getRange('A2:A').getValues(); //capture list of IDs
var data = ss.getSheetByName('data').getDataRange().getValues(); //capture all data
var toPrint = [];
var counter = 1;
for (var i = 0; i < data.length; i++) {
  var temp = data[i];
  var col13 = temp[13];
  for (var j = 0; j < sidList.length; j++) {
    if (col13 == sidList[j][0]) {
      temp.push(counter);
      toPrint.push(temp);
      counter++;
      break;
    }
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading