7 Replies Latest reply on Mar 4, 2019 11:45 AM by Armando Santos

    Worksheet name issue - dashboard.worksheets.forEach(function (worksheet)

    Armando Santos

      Hello.

       

      I am a beginner in developing Tableau Extensions.

       

      I’ve started recently to develop a new extension as per suggestion of Keshia Rose.   

      (TABLEAU version 2018.2)

       

      Now I am facing one un-expected behavior that I need some help or guidance.

      In the below code (index.html) I am struggling to get the worksheet name available on the dashboard and I don’t know the reason of this strange behavior. As you can see below, I’ve tried 3x different approaches but without success.

      My final goal is to draw a chart (for example a Doughnut) with data coming from the Tableau datasource - as per steps within:

      https://tableaumagic.com/creating-a-tableau-extension-part-two/

       

        <script src="js/tableau-extensions-1.latest.min.js"></script>

        <canvas id="doughnut" width="1300" height="900"></canvas>

       

        <script>

       

        //initialise the tableau object, wait for the promise to return and grab the name of the dashboard

      tableau.extensions.initializeAsync().then(() => {

          drawChartJS();

        });

       

         // This javascript function gets data from a specific worksheet and draws the Doughnut.

         function drawChartJS() {

       

         // Gets all the worksheets in a Tableau Dashboard

        

         // 1st option

         let dashboard = tableau.extensions.dashboardContent.dashboard;

         dashboard.worksheets.forEach(function (worksheet) {

            if (worksheet.name === 'worksheetData')

            {      

              alert('The correct sheet!!!');

            }

          });

       

         // 2nd option

         tableau.extensions.dashboardContent.dashboard.worksheets.forEach(function (worksheet){window.alert(worksheet.name)});

       

         // 3rd option

         const worksheets = tableau.extensions.dashboardContent.dashboard.worksheets;

         var worksheet = worksheets.find(function (sheet) {

            return sheet.name === "worksheetData";

         });

       

        // Call a function on the worksheet Object to get the Summary Data

        // worksheet.getSummaryDataAsync().then(function (sumdata) {

        //window.alert("worksheetData is found!!!");

        //});

       

         // Dashboard name     

         window.alert("The dashboard name is ? " + dashboard.name );

       

         // Render the doughnut 

         var options = {

          …

       

      NOTE:

      In the 3rd option if I include the below code then the extension stops.

         // Call a function on the worksheet Object to get the Summary Data.

             worksheet.getSummaryDataAsync().then(function (sumdata) {

                     window.alert("worksheetData is found!!!");

           });

       

       

      I can see in Tableau side that initialization of this extension is working fine (tableau.extensions.initializeAsync()) because I can see the alert popping up with the dashboard name.

      image1.png

      However, I don’t get any alert for the existing worksheets (as you can see below we have 3x sheets + 1x dashboard):

      image2.png

       

      Please advise or suggest any options.

       

      Regards

      Armando Santos

       

      PS .Attached the trex + index (full code) files for your evaluation.