title: Set Sheets filter with Apps Script onEdit using batchUpdate
body: <p>The following example works fine when you manually run the setFilter() function:</p>
  
  <p><a href="https://docs.google.com/spreadsheets/d/1vSDdXU8XSnfG5ixjaMtDys1ynwpbKTptPb_ZFjuMASg/edit#gid=0" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1vSDdXU8XSnfG5ixjaMtDys1ynwpbKTptPb_ZFjuMASg/edit#gid=0</a></p>
  
  <pre><code>function setFilter() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
  
    var filterSettings = {};
  
    // The range of data on which you want to apply the filter.
    // optional arguments: startRowIndex, startColumnIndex, endRowIndex, endColumnIndex
    filterSettings.range = {
      sheetId: ss.getActiveSheet().getSheetId()
    };
  
    // Criteria for showing/hiding rows in a filter
    // https://developers.google.com/sheets/api/reference/rest/v4/FilterCriteria
    filterSettings.criteria = {};
    var columnIndex = 2;
    filterSettings['criteria'][columnIndex] = {
      'hiddenValues': ["England", "France"]
    };
  
    var request = {
      "setBasicFilter": {
        "filter": filterSettings
      }
    };
    Sheets.Spreadsheets.batchUpdate({'requests': [request]}, ss.getId());
  }
  </code></pre>
  
  <p>But the function doesn't work within <code>onEdit()</code></p>
  
  <pre><code>function onEdit(e){
    setFilter();
  }
  </code></pre>
  
  <p>Does <code>batchUpdate</code> not work in <code>onEdit</code>?</p>