2 Replies Latest reply on Apr 19, 2018 2:04 PM by Khoa Tran

    Making WDC url configurable

    Bhavesh Joshi

      I have just started with tableau, I am trying to build a tabeau WDC.

       

      I have a service which interact with database but have no visualization, so I was planning to give user an option to generate WDC using service (the result will be html and json file , which will be given to user), so I don't  want the WDC to be static URL(used to get data ), I wanted to make user enable to specify filters/values based on the use case.

       

      sample example

       

       

          (function () {

              var myConnector = tableau.makeConnector();

         

              myConnector.getSchema = function (schemaCallback) {

                  var cols = [{

                      id: "month",

                      dataType: tableau.dataTypeEnum.string

                  }, {

                      id: "value1",

                      alias: "value1",

                      dataType: tableau.dataTypeEnum.float

                  }, {

                      id: "value2",

                      alias: "value2",

                      dataType: tableau.dataTypeEnum.float

                  }];

         

                  var tableSchema = {

                      id: "testfeed",

                      alias: "test Feed",

                      columns: cols

                  };

         

                  schemaCallback([tableSchema]);

              };

         

              myConnector.getData = function (table, doneCallback) {

                  $.getJSON('http://test.com/view?name=test&filters=[{"type":"number","id_equals":["123"]}]', function (resp) {

         

                      var feat = resp.DATA,

                          tableData = [];

         

                      // Iterate over the JSON object

                      for (var i = 0, len = feat.length; i < len; i++) {

                          tableData.push({

                              "MONTH": feat[I].month,

                              "ChargeEntryLag_NUMERATOR": feat[i]. value1,

                              "ChargeEntryLag_DENOMINATOR": feat[i]. value2

                          });

                      }

         

                      table.appendRows(tableData);

                      doneCallback();

                  });

              };

         

              tableau.registerConnector(myConnector);

              $(document).ready(function () {

                  $("#submitButton").click(function () {

                      tableau.connectionName = "testFeed";

                      tableau.submit();

                  });

              });

          })();

      my URL contains some filters as shown in the above code, so if I want to get data for a particular filter I have to hardcode it in URL and the use it.

      so one of the way which I came across to achieve this is WDC Multiple Tables Tutorial , where user can give the  values , is it the right way or there some other way to do it?

       

      also when to use the init method as described here WDC Custom Initialization and Shutdown

      which one to use in this case.

        • 1. Re: Making WDC url configurable
          Patrick A Van Der Hyde

          Hello Bhavesh,

           

          Just replying here to bring this topic back up in this group.  Have you found a solution since this post?

           

          Patrick 

          • 2. Re: Making WDC url configurable
            Khoa Tran

            I have this similar need to dynamically change the api url for a user.  I was able to create an aspx page out of the WDC instead of using a fixed html file, but it only works in the simulator but NOT in tableau.  What I did was at login, my aspx page prompts the user to log in.  I check the credentials , save the url after it is looked up for user to a page a session variable, then enable the green button to get the data.  At the $.getJSON() function I called a JS function to read the URL saved in the session.  All this works fine when I place the aspx WDC in the Simulator and it will connect to the proper api for a given login and load data.  However, this does NOT work when using that same aspx WDC inside Tableau as the session is read as blank.  The jump from the simulator retains the session info while the leap to Tableau from the popup loses the session to preserve the api url.  Would be nice to know if there is a way to persists this for Tableau.  Anyone able to do something like this?

             

            -KT