1 Reply Latest reply on Mar 15, 2017 4:30 PM by diego.medrano

    Join filtering in WDC not working?

    Volker Kueffel

      I'm new to Tableau and trying to get a WDC to work. Due to the nature of our data, I need to use join filtering to retrieve table for a dependent table, which, according to the documentation is exactly what Join Filtering does: "When you connect to multiple tables of data with a web data connector, you can filter the data from one table based on the data from another table. Said another way, you can make one table dependent on the data returned from another table."

       

      I have a list of media files and the topic those are about (which is a one-to-many relationship). Using the documentation as a guideline I created a schema like this:

       

           var myConnector = tableau.makeConnector();

           myConnector.getSchema = function (schemaCallback) {

           var tables=[

              {

                          alias: "Media",

                          id: 'media',

                          incrementColumnId: 'creationDate',

                          foreignKey: {

                              tableId: "media_topics",

                              columnId: "mediaId"

                          },

                          columns: [

                              { id: "mediaId", alias: "Media ID", dataType: tableau.dataTypeEnum.string },

                              { id: "externalId", alias: "External ID", dataType: tableau.dataTypeEnum.string },

                              { id: "status", alias: "Status", dataType: tableau.dataTypeEnum.string },

                              { id: "contentType", alias: "Content Type", dataType: tableau.dataTypeEnum.string },

                              { id: "mediaLengthSeconds", alias: "Media Length (s)", dataType: tableau.dataTypeEnum.int },

                              { id: "creationDate", alias: "Creation Date", dataType: tableau.dataTypeEnum.date }

                          ]

                      },{

                          alias: "Media Topics",

                          id: 'media_topics',

                          joinOnly: true,

                          columns: [

                              { id: "mediaId", alias: "Media ID", dataType: tableau.dataTypeEnum.string, filterable: true},

                              { id: "topic", alias: "Topic", dataType: tableau.dataTypeEnum.string }

                          ]

                      }

              ];

               schemaCallback(tables);

              };

       

      What strikes me as odd is the fact that the foreign key is actually defined on the referenced table, making it impossible to have multiple tables depend on that one..., but I guess there is some reason for that...

       

      Then to collect the data I have (which is almost an exact copy of the example):

       

      myConnector.getData = function (table, doneCallback) {

                  var apiBase = 'https://some.server.net/api' ;         

                  if (table.tableInfo.id==='media') {

                    

                      var lastDate=table.incrementValue;

                      var url=apiBase+"/some/path";

                      if (lastDate) {

                          url+="&lastTS="+lastDate;

                      }

                    

                      $.getJSON(url, function(resp) {

                          var feat = resp,

                          tableData = [];

        

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

                            

                              tableData.push({

                                  "mediaId": feat[i].mediaId,

                                  "externalId": feat[i].externalId,

                                  "status": feat[i].status,

                                  "contentType": feat[i].contentType,

                                  "mediaLengthSeconds": feat[i].mediaLengthSeconds,

                                  "creationDate": feat[i].creationDate

                              });

                            

                          }

            

                          table.appendRows(tableData);

                          doneCallback();

                      });

                  } else if (table.tableInfo.id==='media_topics') {

       

                      if (!table.isJoinFiltered) {

                          tableau.abortWithError("The table must be filtered first.");

                          return;

                      }

       

                      if (table.filterValues.length === 0) {

                          doneCallback();

                          return;

                      }

       

                      var ids=table.filterValues.join(',');

                      var url=apiBase+"/some/other_path?ids="+ids;

                    

                      $.getJSON(url, function(resp) {

                          var feat = resp,

                          tableData = [];

        

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

                              tableData.push({

                                  "mediaId": feat[i].mediaId,

                                  "topic": feat[i].topic

                              });

                          }

            

                          table.appendRows(tableData);

                          table.filterValues=[];

                          doneCallback();

                      });

       

                  }

                

              };

            

      Loading the "media" data works perfectly fine, including the incremental update. However the message "The table must be filtered first." pops up every time Tableau is updating data, whether in the data source section or on the worksheet. Am I missing a step here?