0 Replies Latest reply on Nov 18, 2019 11:33 AM by Rohan Singh

    getUnderlyingDataAsync() is taking time to load data

    Rohan Singh

      Hi All, I am trying to read data from a Tableau sheet using JavaScript API.

      I am using 'getUnderlyingDataAsync()' function to get all the rows. The main reason for not using 'getSummaryDataAsync()' function is, I am planning to create filters in JS and to have a single "Apply" button for all the filters.

      The problem I am facing is, the sheet from which I am getting data has around 330K records. Below is the sample code I am using. Total execution time is ~50 seconds and out of that getUnderlyingData() function is in the wait state for ~40 seconds(This stat is from Firefox Inspect Element-->Network tab).

      function initViz() {
          var containerDiv = document.getElementById("vizContainer"),
              url = "[URL to Tableau Dashboard]"
          options = {
              hideTabs: true,
              hideToolbar: true,
              onFirstInteractive: function () {
                  getUnderlyingData();
              }
          };
          viz = new tableau.Viz(containerDiv, url, options);
      }
      
      function getUnderlyingData() {
          sheet = viz.getWorkbook()
              .getActiveSheet()
              .getWorksheets()
              .get("[Sheet Name]");
          var options = {
              maxRows: 0,
              ignoreAliases: false,
              ignoreSelection: false,
              includeAllColumns: false
          };
          sheet.getUnderlyingDataAsync(options)
              .then(function (t) {
                  table = t;
                  var data = table.getData();
                  var columns = table.getColumns();
      //function to map data to columns
                  function reduceToObjects(cols, data) {
                      var fieldNameMap = $.map(cols, function (col) {
                          return col.$0.$1;
                      });
                      var dataToReturn = $.map(data, function (d) {
                          return d.reduce(function (memo, value, idx) {
                              memo[fieldNameMap[idx]] = value.formattedValue;
                              return memo;
                          }, {});
                      });
                      return dataToReturn;
                  }
                  var dataTable = reduceToObjects(columns, data);
              })
      }
      

       

      Is there anything that I am doing wrong or there is any other way to handle this issue?

       

      Thanks