title: How to get values for filtered range with Apps Script
body: <p>I need to get the range values for my spreadsheet - but only those rows displaying by virtue of the currently-selected filter. </p>
  
  <p>I have tried using <code>getValues()</code> on <code>sheet.getFilter().getRange()</code>:</p>
  
  <pre><code>function applyOverdueFilter() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();
  
    var filter1 = SpreadsheetApp.newFilterCriteria();
    filter1.whenDateBefore(SpreadsheetApp.RelativeDate.TODAY);
  
    sheet.getFilter().setColumnFilterCriteria(4, filter1.build());
  
    var newData = sheet.getFilter().getRange().getValues(); // this doesn't work
    Logger.log(newData);
  }
  </code></pre>
  
  <p>However, <code>newData</code> contains all the data in my spreadsheet, not just the data showing with the filters applied. How do I only get the filtered data?</p>
  
  <p>Notes: the sheet already has a filter and everything up until the last two lines works perfectly. The reason I don't want to use array filtering in JavaScript is because my filters concern dates and relative dates, which are a lot easier to filter for with Apps Script's Filter Criteria.</p>