3 Replies Latest reply on Dec 18, 2019 12:51 AM by Varsha Sen

    Welcome to the Extensions API Forum!

    Keshia Rose

      With the launch of the Extensions API, we thought we would create a space in our community to talk all about them. Have a question about the API? Ask away! Found a bug? Let us know! Have an idea for a cool extension or want to know if something is already available? Here is the place to talk about it.

       

      Also, if you haven't tried making an extension of your own yet, check out these resources!

       

      We are so excited about launching Extensions and we can't wait to hear from you!

       

      Keshia Rose

      Product Manager, Developer Evangelism

        • 1. Re: Welcome to the Extensions API Forum!
          anicet.kebou

          Hello Rose,

          thank for introducing Extension API. I have started to use extensions and have following issue:

           

          I would like to create a tableau extension to get data (summary) from a worksheet (customers worksheet), to customize these data and then show the customized data by clicking "show data" button. I have used the "worksheet.getSummaryDataAsync()" method to get data. But when i filter the worksheet and click "show data" , all the data are shown not the filtered data. Can you support me for this issue?

           

          How get i get the current data of the worksheet??

           

           

           

          Here the javascript code for the extension:

           

           

           

           

           

           

           

          (function() {

           

           

           

              // Declare array for Handler functions

           

              let unregisterHandlerFunctions = [];

           

           

           

           

           

              // Declare data array

           

              let data = [];

           

           

           

           

           

           

           

            //-----------------------------------------------------------------------------------------------------------------------------------------------

           

           

           

              // Use the jQuery document ready signal to know when everything has been initialized

           

              $(document).ready(function() {

           

           

           

                  const table = $('#parameterTable');

           

                  const tableBody = table.children('tbody');

           

           

           

                  //alert('TEST');

           

                  // Tell Tableau we would like to initialize our extension

           

                  tableau.extensions.initializeAsync().then(function() {

           

           

           

           

           

                    

           

           

           

                      //initialize data

           

                      initializeData();

           

           

           

           

           

                      //call an operation for each button after clicking

           

                      $('#showDataButton').click(showData);

           

                   

           

           

           

           

           

                  }, function(err) {

           

           

           

                      // error while initializing.

           

                      alert('Error while Initializing: ' + err.toString());

           

                  });

           

           

           

              });

           

           

           

           

           

           

           

           

           

          //--------------------------------------------------------------------------------------------------------------------------------------------------

           

           

           

           

           

              // This javascript function gets the current data of the worksheet.

           

              function initializeData() {

           

           

           

           

           

                  // clear array

           

                  data.clear;

           

           

           

           

           

                  // Gets all the worksheets in a Tableau Dashboard

           

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

           

           

           

                  // Finds a worksheet called "Case overview"

           

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

           

                      return sheet.name === "Customers";

           

                  });

           

           

           

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

           

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

           

           

           

                      // We get our summary data:

           

                      var worksheetData = sumdata.data;

           

           

           

                   

           

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

           

           

           

                          //data.push(worksheetData[i][2].formattedValue);

           

                          //get only customer Name

           

                          data.push(worksheetData[i][1].value);

           

                      }

           

           

           

           

           

                  });

           

                

           

                 

           

              }

           

           

           

           

           

           

           

           

           

              //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

           

           

           

              function showData() {

           

           

           

                 //show the data

           

                 alert(data);

           

              

           

              }

           

           

           

           

           

           

           

           

           

           

           

          })();

          • 2. Re: Welcome to the Extensions API Forum!
            Keshia Rose

            Hi Anicet,

             

            Sorry for the delayed response. I took a look at your code and I can see why you are not getting the filtered data. It's because you currently only get the data once and then never update it to match the filters. Your current process is like this: Extension Initialized >> Get the data >> Store the data. Then you have a button that retrieves that stored data [Push the button >> Display the stored data]. If you change a filter and push the button again you will receive the same data because you only get the data on initialization and haven't done anything to change the stored data. You can do this by either listening to the worksheet for filter changes and then update the data, or preferably, only collect the data when the button is pushed. That process would look like this: Extension Initialized then when the user is ready, or any time after filters have been set Push the button >> Get current data >> Display the data. Hope it helps! - Keshia

             

                  (function() {
                    $(document).ready(function() {
                      tableau.extensions.initializeAsync().then(
                        function() {
                          $("#showDataButton").click(getData);
                        },
                        function(err) {
                          alert("Error while Initializing: " + err.toString());
                        }
                      );
                    });
            
                    function getData() {
                      let data = [];
                      const worksheets = tableau.extensions.dashboardContent.dashboard.worksheets;
                      var worksheet = worksheets.find(function(sheet) {
                        return sheet.name === "Customers";
                      });
            
                      worksheet.getSummaryDataAsync().then(function(sumdata) {
                        var worksheetData = sumdata.data;
                        for (var i = 0; i < worksheetData.length; i++) {
                          data.push(worksheetData[i][1].value);
                        }
                        // DO STUFF WITH THE DATA HERE (Example: Display in a table)
                        console.log(data);
                      });
                    }
                  })();
            
            • 3. Re: Welcome to the Extensions API Forum!
              Varsha Sen

              Hi,

               

              I have the same requirement. Can you please share the custom extension you created as I'm new to this.

               

              Thanks,

              Sen