0

Newbie to scripting here...

I've successfully used a script based on this post:
Google Script for Sheets: Set multiple filters

How may I adjust the code to set the filter to prevent all non-blank entries for appearing? I've tried variations of Null, "", BLANK with no success.

function setFilters() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheetByName("Project Tracker");
  var rang = sh.getDataRange();
  var filtercriteria = SpreadsheetApp.newFilterCriteria().setHiddenValues(["Completed","Cancelled"]).build();//used Cancelled NOT Canceled; Create criteria with two hidden values
  var filter = rang.getFilter() || rang.createFilter();// getFilter already available or create  a new one
  filter.setColumnFilterCriteria(2, filtercriteria);//set the criteria against Col2 (B column)
}

Most appreciated.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Ross Davis
  • 11
  • 1

1 Answers1

0

Answer: use single quotes for the hidden values.

So... setHiddenValues(['Completed','Canceled',''])

This is the completed function. The only differences are single quotes around the words Completed and Canceled (sic) and two single quotes ''which identify "Blanks".

function so_53596113() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheetByName("Project Tracker");
  var rang = sh.getDataRange();
  var filtercomplete = SpreadsheetApp.newFilterCriteria().setHiddenValues(['Completed','Canceled','']).build();//Create criteria with two hidden values
  var filter = rang.getFilter() || rang.createFilter();// getFilter already available or create  a new one
  filter.setColumnFilterCriteria(3, filtercomplete);//set the criteria against Col3 (C column)
}

This is a valuable question. Google's documentation is non-existent and at the time of writing there are no other internet resources which cover this issue.

Credit to DanCue, who was also researching Filters, for the idea to run the macro editor, look at that code and adapt it for the function.

Tedinoz
  • 5,911
  • 3
  • 25
  • 35