5 Replies Latest reply on Jun 24, 2016 7:30 PM by Russell Christopher

    Javascript API Error: activeSheet.applyFilterAsync is not a function

    Nay Lin Soe

      Hello all,

       

      I've just started using JS API by following the tutorial. I've tried to reproduce the first two steps in the tutorial--show the dashboard and filter. However, although I can display the dashboard successfully, when I try that for filtering, nothing happened (the Fire Bug in my browser is saying activeSheet.applyFilterAsync is not a function).

       

      I've attached the html file and the js file for reference ('dev' for both id and password). The js file is exactly the same as the one that comes with the tutorial, except that the url has been changed, and in filterSingleValue(), the value has been changed from "The Americas" to "A". The originals appear as comments next to them.

       

      Could anyone point out what I have done wrong here? Thanks in advance.

       

      Nay

        • 1. Re: Javascript API Error: activeSheet.applyFilterAsync is not a function
          Nay Lin Soe

          Actually I've found the answer myself. activeSheet variable was actually pointing to a dashboard. Since we cannot act directly on the dashboard, all I have to do was:

          activeSheet.getWorksheets().get("Sample1").applyFilterAsync("Region",
                                      "A",
                                      tableauSoftware.FilterUpdateType.REPLACE);

          And it works fine now.

          • 2. Re: Javascript API Error: activeSheet.applyFilterAsync is not a function
            Russell Christopher

            Hey Nay -

             

            The problem here is that it looks like you're attempting to filter your dashboard, rather than the sheet WITHIN your dashboard. Here's an example that selects marks in a sheet inside a dashboard. It should give you an idea of how to get a reference to the sheet in the dashboard so you can filter it directly.


            HTH.

             

                // First, access the workbook. Ask for the active sheet (getActiveSheet), which will be sheet
                // "Dashboard"
                // (assuming that the Dashboard sheet has focus). Ask the Dashboard sheet for the the collection
                // of worksheets it contains (getWorksheets). Finally, pull "Profit v. Sales" from that collection and assign it
                // to a variable
                mainWorkbook = mainViz.getWorkbook();
                var worksheet = mainViz.getWorkbook().getActiveSheet().getWorksheets().get("Profit v Sales");
            
            
                worksheet.selectMarksAsync("Category", "Technology", "REPLACE");
            
            • 3. Re: Javascript API Error: activeSheet.applyFilterAsync is not a function
              Nay Lin Soe

              Thanks Russell. I managed to figure it out myself and posted the response as a reply to myself (just 11mins before your post--you had already begun typing by then I guess).

              • 4. Re: Javascript API Error: activeSheet.applyFilterAsync is not a function
                anastasia aourik

                Have you ever had more than one viz (from 2 entirely different projects/environments) and both have YEAR field.

                Now I would like to use TABLEAU JS to display both vizes next to each other (inline-block) at the same time

                AND

                using a single <select year tag onclick call FilterYear and apply year filter to viz1 and then to viz2...

                 

                I can't get this to work...

                • 5. Re: Javascript API Error: activeSheet.applyFilterAsync is not a function
                  Russell Christopher

                  There is no simple way to make this work - you'll have to manage applying the filter to both vizzes yourself. There are probably a couple ways to do this:

                   

                  • Show the filter from one/or the other viz and then put an event listener on it. When the user changes the value (impacting workbook1), your event listener will fire and then you'll have additional code which reads what the filter was changed to and apply that value to the second viz.
                  • Use a 3rd party "year picker" and use the JS API to apply the selection to both sheets.