2 Replies Latest reply on Jul 16, 2015 7:43 AM by Ryan Morgan

    JS API Marks and Dashboards

    Ryan Morgan

      Attempting to write a basic statement to highlight marks on a dashboard. So far my statements work fine with all filtering actions.

       

      Using the public example:

      http://public.tableau.com/views/Presents/TreeMap

       

       

      I created a select marks statement for electronics:

      function selectMarks (filterName, values) {

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

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

        sheet.selectMarksAsync(filterName, values, 'REPLACE');  <!--show only values selected-->

        } else {

        worksheetArray = sheet.getWorksheets();

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

        worksheetArray[i].selectMarksAsync(filterName, values, 'REPLACE');

        }

        }

      }

       

      However what I'm noticing is that the selection isn't looping to every sheet on the dashboard.  Same situation with clearSelectedMarksAsync()

       

      Am I doing something wrong?

        • 1. Re: JS API Marks and Dashboards
          Joshua Swickard

          Using that public example:

           

          function selectMarks() {

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

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

            sheet.selectMarksAsync("Category", "Doll", tableau.SelectionUpdateType.REPLACE); 

            } else {

            worksheetArray = sheet.getWorksheets();

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

            worksheetArray[i].selectMarksAsync("CategorSub-Category", "Paper", tableau.SelectionUpdateType.REPLACE);

           

          worksheetArray[i].selectMarksAsync(

            "City", "Rapid City", tableau.SelectionUpdateType.REPLACE);

           

            }

            }

          }

           

           

          function clear_AllMarks()

          {

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

            if (sheet.getSheetType() === 'worksheet')

          {

            sheet.clearSelectedMarksAsync();

          } else {

            worksheetArray = sheet.getWorksheets();

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

          {

            worksheetArray[i].clearSelectedMarksAsync();

          }

          }

          }

           

          Using:

          http://public.tableau.com/views/interactive-dash-234578192/DashboardFilters

           

          function selectMarks() {

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

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

            sheet.selectMarksAsync("City", "Rapid City", tableau.SelectionUpdateType.REPLACE); 

            } else {

            worksheetArray = sheet.getWorksheets();

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

           

          worksheetArray[i].selectMarksAsync(

            "City", "Rapid City", tableau.SelectionUpdateType.REPLACE);

           

            }

            }

          }

           

          I'm not 100% sure what the issue you experienced was since I don't know what you were passing for filtername and values, but these values do work for each of those views.  Your looping logic does look fine, although I think marks selection is a little trickier than highlighting since the ways dashboards are designed often mean underlying filtering works on two dashboards but the individual marks on each are different.

           

          There are a few other examples here:

          http://onlinehelp.tableau.com/current/api/js_api/en-us/help.htm#JavaScriptAPI/js_api_concepts_selecting_marks.htm

          1 of 1 people found this helpful
          • 2. Re: JS API Marks and Dashboards
            Ryan Morgan

            Josh,

            I apologize for the delay.  I have not had a chance to test this out this week but I will run through tonight and confirm this is the correct answer.

             

            I'm marking helpful until I can confirm, hopefully tonight I can close this answer out.

             

            Thank you very much for the quick reply!