5 Replies Latest reply on Mar 5, 2019 9:37 AM by Yiping Zhang

    Setting tableau filters via JS across multiple dashboards/worksheets

    Tommy Harstrom

      We have a workbook which contains two dashboards, the first contains one worksheet and the second contains four worksheets.

      We're trying to pass filters in via the url (that part is ok) but we cannot get all the worksheets on the second dashboard to update.

      The code loops through the dashboards, activating each in turn then calling a filterActiveSheet() method on each.

      This method loops through each worksheet in turn, searches for a matching categorical filter with the same FieldName as the provided one and, when found, uses the applyFilterAsync() method to replace it with the provided one.


      var options = {
      < snip >
      : function () {
      = viz.getWorkbook();
      = workbook.getPublishedSheetsInfo();
      for(s = 0; s < sheets.length; s++)

      function filterActiveSheet(sheet) {
      for (ws = 0; ws < sheet.getWorksheets().length; ws++) {
      var worksheet = sheet.getWorksheets()[ws];
      .then(function(p) {
      var f = filters.split(';');
      var filter = f[y].split(':');  
      var filterType = $.grep(p, function(e){ return e.getFieldName() == filter[0]; });
      if (filterType.length > 0) {
      switch(filterType[0].getFilterType()) {
      case tableau.FilterType.CATEGORICAL:
      return worksheet.applyFilterAsync(filter[0], filter[1], tableau.FilterUpdateType.REPLACE);
      < snip >

      var viz = new tableauSoftware.Viz(placeholderDiv, url, options);


      The problem we're seeing is that only one worksheet on each dashboard is being updated. Stepping through the JS in Chrome I can see the call to applyFilterAsync() the expected number of times which does not seem to cause an error, it simply doesn't seem to want to update all the filters/worksheets, just one on each dashboard.

      Thoughts? Suggestions? Syntax errors?