2 Replies Latest reply on Jul 11, 2018 1:59 PM by Keshia Rose

    WDC import working with simulator not with Tableau Desktop

    Roy Wang

      I can get the simulator working with a basic variant of from the Getting Started docs, but when importing to Tableau, I get just one value returned.

       

      I need to loop and call the API several times to get historical data.

       

      I read that this has something about asynchronous data transfer and when to execute the callback function. I also read that Promise would be good here, but I'm a little fuzzy on exactly how to call it (Promise (resolve, reject)) Where exactly does my get  function and the call back live?

       

      Since I couldn't get that to work I tried something along these lines and it also didn't work. If someone could look at this I'd appreciate it

       

       

       

      (function () {var myConnector = tableau.makeConnector();
                      myConnector.getSchema = function (schemaCallback) {
                     var cols = [{
                             id: "date",
                             dataType: tableau.dataTypeEnum.date
                     },{
                             id: "rate",
                             dataType: tableau.dataTypeEnum.float
                                    }];
                     var tableSchema = {
                            id: "EuroFX",
                             alias: "Daily Euro-USD Exchange Rates via Fixer API",
                             columns: cols
                     };
                     
                     schemaCallback([tableSchema]);        
                     
              };
              
              function getDataForDate(date_string, successCallback) {
                     return $.getJSON("http://data.fixer.io/api/" + date_string + "?access_key=xxxxxx&symbols=USD"), successCallback();
                     };
              myConnector.getData = function (table, doneCallback) {
                     var combinedData = [],
                             deferred = [];
                     var now = new Date();
                     var date_looper = new Date(2018,5,1);
                     while (date_looper < now){
                             var date_string  = date_looper.getFullYear() + '-'
                                     + ('0' + (date_looper.getMonth() + 1)).slice(-2) + '-'
                                     + ('0' + (date_looper.getDate())).slice(-2);
                             
                             deferred.push(getDataForDate(date_string, function (data) {
                                     combinedData = combinedData.concat(data);
                                     }));
                             date_looper.setDate(date_looper.getDate() + 1);        
                     }
                     
                     $.when(deferred).done(function() {
                             table.appendRows(combinedData);
                             doneCallback();
                     });
                     
                     };
                     
              
              
              tableau.registerConnector(myConnector);
       
                     $(document).ready(function () {
                             // The event listener below isn't necessary when writing for running without user input
          $("#submitButton").click(function () {
              tableau.connectionName = "FX Rate Feed";
              tableau.submit();
          });
      });
       
      })();