1 Reply Latest reply on Aug 17, 2015 10:57 AM by Shawn Wallwork

    Report initialization from external parameter values

    Rick Hutchison

      Hi Tableau Community,

       

      A tableau dashboard has been embedded within a SharePoint page.  The SharePoint devs created a custom filter value selection page with the purpose of filtering both SharePoint and Tableau with the same values.  The number and string size of the filter values exceeds the 2000 byte limit of a URL.

       

      The API offers hope that we can apply the filters via javascript.  The code below works in Chrome, but with a side effect.

       

      Putting the initial filter in onFirstInteractive causes the report to render with no filters, then render again with the filter applied.

       

      Is there any way to apply the filters for the first render via the API without appending them to the URL?  Alternatively - can I hide or prevent the showing of the first no-filters-applied render and just show the 2nd filtered rendering of the dashboard reports?

       

      <html>

      <head>

      <meta charset="utf-8">

      <title>Tableau 8 Javascript API</title>

      <script type="text/javascript" src="http://public.tableausoftware.com/javascripts/api/tableau_v8.js"></script>

      <script type="text/javascript">

      /////////////////////

      // Global variables

      var viz, workbook, activeSheet

       

       

      // Change the Facility filter

      function filterValue() {

        activeSheet.applyFilterAsync(

          "Facility",

        "MyValue1",

        //can also iterate and apply multiple filter values here.

        //["Some Filter Value 1", "Some Filter Value 2"],

          tableauSoftware.FilterUpdateType.REPLACE);

      }

       

       

      // Initialize the viz to hold the workbook

      function initializeViz(){

          var placeholderDiv = document.getElementById("tableauViz");

          var url = "https://myserver/t/extranet/views/ArrangementTypeDashboardsdynamic/ArrangementTypeDashboard";

          var options = {

              width: "1200px", //width: placeholderDiv.offsetWidth,

              height: "800px", //height: placeholderDiv.offsetHeight,

              hideTabs: true,

              hideToolbar: true,

              onFirstInteractive: function () {

                  workbook = viz.getWorkbook();

                  activeSheet = workbook.getActiveSheet();

        if(activeSheet.getSheetType() === 'worksheet') {

           // or call the filterValue() function instead of the next line.

           activeSheet.applyFilterAsync("Facility","MyValue1",'REPLACE');

        } else {

           worksheetArray = activeSheet.getWorksheets();

        for(var i = 0; i < worksheetArray.length; i++) {

         worksheetArray[i].applyFilterAsync("Facility","MyValue1",'REPLACE');

        }

        }

              }

          };

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

      }

      </script>

      </head>

      <body>

          <div id="tableauViz" style="height:1200px; width:1200px"\></div>

          <script type='text/javascript'>

          initializeViz();

          </script>

      </body>

      </html>

       

      Thanks,

      Rick