3

I have created some Google Apps Script code which creates GSheets FilterViews. I cannot see how to apply a specific FilterViews (not Filters) to the current sheet.

The code i have sets FilterSettings and then applies it to a basic filter but i cannot see in the documentation how to apply a similar approach to filterview.

if (condition!=0 && hiddenValues.length>0)
  {
    filterSettings['criteria'][COLUMNS.ASSIGNEE.pos] = {
      'hiddenValues': hiddenValues,
      'condition': condition
    };    
  }
  else if(hiddenValues.length>0)
  {
    filterSettings['criteria'][COLUMNS.ASSIGNEE.pos] = {
      'hiddenValues': hiddenValues,
    };    
  }
  else if(condition!=0)
  {
    filterSettings['criteria'][COLUMNS.ASSIGNEE.pos] = {
      'condition': condition
    };    
  }

  // Using BASIC FILTER not FILTER VIEW   
  var request = {
    "setBasicFilter": {
      "filter": filterSettings
    }
  }

Sheets.Spreadsheets.batchUpdate({'requests': [request]}, ss.getId());

Have looked at this doc:-

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/sheets#FilterView https://developers.google.com/sheets/api/reference/rest/v4/FilterCriteria https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#ConditionType https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#ConditionValue

I can see that historically its not been supported but I wonder if that is still the case.

I can see if i look at the requests API there are request types for:-

  • addFilterView
  • deleteFilterView
  • updateFilterView
  • duplicateFilterView

There is no SetFilterView.

What is the right way to activate a filter view via GAS.

Thanks

Rubén
  • 34,714
  • 9
  • 70
  • 166
Simon Taylor
  • 607
  • 1
  • 9
  • 27
  • 2
    Possible duplicate of [How to apply a GoogleSheet Filterview via Google Apps Script?](https://stackoverflow.com/questions/57785797/how-to-apply-a-googlesheet-filterview-via-google-apps-script) – ziganotschka Sep 09 '19 at 15:51

0 Answers0