4 Replies Latest reply on Aug 6, 2015 7:59 AM by Amit Yeshayahu

    Javascript API - Select marks in a dashboard with multiple worksheets

    Jason Gill

      I have a dashboard with one worksheet at the top that gets marked to filter the worksheet below to display the flights.  I use an outside control (not in tableau) to search for flights and use the javascript api to select those "Flight Records" in Tableau.

       

      When flights selected (outside of Tableau), then do the following:

       

      var activeSheet = this.m_workbook.getActiveSheet();

       

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

          activeSheet.selectMarksAsync(

              "Flight Record",

              newFlights,

              "replace"

          );

      } else if (activeSheet.getSheetType() == "dashboard") {

       

      var sheets = activeSheet.getWorksheets();

           for (sheet in sheets) {

                sheet.selectMarksAsync(

                     "Flight Record",

                     newFlights,

                     "replace"

                );

           }

      }

       

      The problem is that even though the first worksheet doesn't contain "Flight Record" to select, it tries to set the marks, and since it doesn't find "Flight Record", it clears the filtering.

       

      Is there any way in the javascript API to find out what the marks data will contain when no mark has been selected?  What I thought I could do is look at the marks for a worksheet, see if "Flight Record" is a field, if so, then I could perform the selection on that worksheet.

        • 1. Re: Javascript API - Select marks in a dashboard with multiple worksheets

          Hey Jason,

           

          I'm moving this to our developer community where it's more likely to receive a response.

           

          Thanks!

           

          Diego

          • 2. Re: Javascript API - Select marks in a dashboard with multiple worksheets
            Russell Christopher

            Hey Jason -

             

            I'm not 100% sure I'm following what you wrote, but is sounds like that you select marks in the first viz based on "flight record" and then loop through the other vizzes, trying to select marks with the same dimension values. Problem is, some of these "other vizzes" don't contain that dimension at all.

             

            Forget the API altogether for a moment:

             

            • Please explain why you want to select the same marks in the other vizzes. Based on your reason, there may be an entirely different approach to take
            • Are there any related fields between the first viz and vizzes 2-N that you could lean on? For example, if you created an action filter in Tableau, how could clicking a bar in the bar chart select/filter circles in your scatter plot?

             

            When all is said and done we need something to filter/select with on vizzes 2-N - and no, there is no way to grab data from behind marks which haven't been selected.

            • 3. Re: Javascript API - Select marks in a dashboard with multiple worksheets
              Jason Gill

              We have a flight searcher form on our site, and when the user does a search, a list of flights are displayed.  On a single tableau worksheet, this works well to select the marks of flights that we have found through the search.

               

              In the example above, I was hoping to select a set of flight records using the top worksheet, and then use our search to filter the flights even further.

               

              I however would like to leave it up to the workbook designer to setup how they would like the individual marks to be displayed before they do a search.

               

              Perhaps I'm going about this wrong and what I need to do is have each of these on different tabs rather than a single dashboard.  They would select a set of flight records, and then it would switch to the other tab/worksheet with the flight records displayed on a single worksheet where we could then filter the selection further.

              • 4. Re: Javascript API - Select marks in a dashboard with multiple worksheets
                Amit Yeshayahu

                Hi ,

                 

                I'm experience  related odd behavior ,  i have a dashboard  with two sheets ,  got the worksheets object   ,but i want to select the marks in sheet 2 for example .

                 

                I wrote  something like this :

                 

                worksheet[j].selectMarksAsync(

                                        "dummy2", "b", tableau.SelectionUpdateType.REPLACE);

                 

                i succeeded to select the marks on the worksheet but it created a loop   for some reason ,why does it happens  ?

                 

                 

                Thanks! ,

                Amit