1 Reply Latest reply on Feb 13, 2020 11:39 AM by Ravi Desai

    Web Data Connector - Making Schema Dynamic.

    Udit Joshi

      Instead of defining schema in your java script code , how to make the schema dynamic ?  I want to pick the same schema which is being dynamically called in the API. So for instance new columns are added in my API schema they will also be added in my java script code in my web data connector. 

       

      My main concern is how will tableau understand the data type if we make the schema dynamic ?

       

      Need guidance around this requirement.

        • 1. Re: Web Data Connector - Making Schema Dynamic.
          Ravi Desai

          We do this with our WDC.  Essentially, we use the WDC to present data available via an API as tables and columns in tableau.  We require authentication, which gives the user associated roles and privileges.  Based on those roles and privileges, the data the is presented via the API can vary dramatically.

           

          The connector.getSchema function in our WDC calls our API to retrieve the set of tables (and what columns are in them) based on your user context.  It issues an XHR (XMLHttpRequest, although you could use an ajax call as well) and in the `onload` callback takes the results of the REST call and formulates the required table schema before calling `schemaCallback`.

           

          The connector.getData function performs very similarly.  It takes the table name (as constructed for the getSchema function) and makes another XHR REST call to our server to respond with the proper data for that table (again, filtered based on the user context).  In the `onload` callback of the XMLHttpRequest, it constructs each row and calls table.appendRows, before calling the doneCallback() when it is complete.

           

          Really the only "trick" is the the schema retrieval call in our REST API has to return table names that it can recognize in the data retrieval call later.  Otherwise, it's all pretty straightforward.  The reason for the schemaCallback and doneCallback functions is so you can perform asynchronous calls (in our case REST calls) in your WDC.