5 Replies Latest reply on Nov 7, 2016 6:02 AM by Hardik Hirpara

    Proper name of action filter in a dashboard

    Adam Huitt

      I have a dashboard that includes several different worksheets.  There are several action filters created to filter the different worksheets.  All of this is working fine.  But I want to use the javascript api to reference a particular worksheet and set the action filter selection - and also to clear an action filter selection.  I've been trying to use applyFilterAsync("[name]","[value]") and clearfilterAsync() but have had no luck.  It seems like this should be so simple.  But I don't know how to get the name of the action filter.  When I go to the menu item for Dashboard and click on Actions I see the name there (it is "LOB").  Then when I see it referenced in other places I see "Action (LOB.LOB.LOB)".  I can actually debug and loop through the worksheets and all the filters to find the exact filter I need, but there is no "name" property....  How do I get the proper name of the action filter?  Thanks for the help!

        • 1. Re: Proper name of action filter in a dashboard
          Hardik Hirpara

          Hello Adam,

           

          Please try with below code :

           

          First add all filters in initViz function inside url as option like below :

          Var url = "Your Embed url" ,

          options = {

            "YEAR(Order Date)": "" ,

            "State":"",

             hideTabs: true

          };

          viz = new tableau.Viz(containerDiv, url, options);

           

          1) For Apply Filter :

            workbook = viz.getWorkbook();  // Retrieve my workbook

            Activesheet= workbook.getActiveSheet(); // Retrieve my active sheet

            Activesheet.applyFilterAsync("State", "ABC", tableauSoftware.FilterUpdateType.REPLACE); // Apply Filter on Action Filter Note: "State" is name of Filter please see the screen shot

           

          1.png

           

          2) For Clear Filter :

          sheet.clearFilterAsync("State");

           

          Please let me know if you want more detail.

           

          Thanks,

          Hardik

          • 2. Re: Proper name of action filter in a dashboard
            Adam Huitt

            So your comments didn't completely work.  But they did get me to try changing the value of the filter when the viz is loaded/init.  The title of the filter was edited so it shows something other than the real name above the filter - so that didn't work.  But I used the filter name in my list of actions under the dashboard menu and when I initialized the viz and put that action name in the options it worked!  So the name given in the actions list is definitely the name I need to use.

             

            When I try to get my external button to change the value of the selected action filter, it doesn't seem to work. I added the filter name to my init options for the viz, then I have the following code when I click my button:

                 sheet = viz.getWorkbook().getActiveSheet();

                 worksheets = sheet.getWorksheets();

                 HCBS = worksheets[0];

                 HCBS.applyFilterAsync("LOB","MS1TP",tableauSoftware.FilterupdateType.REPLACE);

             

            When I click the button it dims the chart and shows the "working" symbol, then just returns to the page and nothing changes.  When I debug, it walks through the code without error and seems to submit the function properly.

             

            Any ideas why it's not updating the viz?  Thank you for the help!

            • 3. Re: Proper name of action filter in a dashboard
              Hardik Hirpara

              Hello Adam,

               

              If possible can you please share your javascript code with me ?

              So I can check it at my end and resolve it asap and revert back to you.

               

              Thanks,

              hardik

              • 4. Re: Proper name of action filter in a dashboard
                Adam Huitt

                Here is a shot of the actions list:

                Capture.PNG

                 

                Here is the script:

                 

                <script src="https://[internal server address]/javascripts/api/tableau-2.js" type="text/javascript"></script>

                <script type="text/javascript">// <![CDATA[    

                 

                function initViz() {        

                     var containerDiv = document.getElementById("vizContainer"),        

                          url = "https://[internal server address]//t/ISGSTest/views/MAAPLaborDashboard/RotaryMissionSystemsLaborDashboard?:embed=y";         

                          options = {hideTabs : true, hideToolbar: false, "LOB" : ""};        

                     viz = new tableau.Viz(containerDiv, url, options);    

                }

                 

                function filterLOB(){

                        sheet = viz.getWorkbook().getActiveSheet();

                                worksheets = sheet.getWorksheets();

                                var HCBS = worksheets[0];

                                HCBS.applyFilterAsync("LOB","C4USS", tableauSoftware.FilterUpdateType.REPLACE);     

                 

                initViz();

                 

                // ]]></script>

                 

                <input onclick="filterLOB();" type="button" />

                • 5. Re: Proper name of action filter in a dashboard
                  Hardik Hirpara

                  Hello Adam,

                   

                  I am not sure. but I think this is not possible.

                  As per my knowledge using applyFilterAsync('--') method, we can apply filter on worksheet only means with filter panel. May be I am wrong.

                   

                  Your concept is very good. I will try if possible to resolve it.

                   

                  Thanks,

                  Hardik