Unknown User
Unknown User

Reputation: 3668

Tableau Custom Web Data Connector

I'm trying to create a custom web data connector, I used the sample what was given in the Tableau Web Data Connector tutorial.

I have a link which returns me the data in JSON, and I pass the url in the jquery AJAX function and tried to console.log the results.

But unfortunately, I'm getting an error as mentioned below.

Uncaught WDC error: Uncaught TypeError: Cannot read property 'results' of undefined   stack:TypeError: Cannot read property 'results' of undefined

When I do a AJAX request with jquery without using the tableau web data connector js file, I'm able to retrieve the data from the link we've created.

And when I compared the results of yahooapi and the link what we've created, the data was in this format.

Yahoo API:

Object{*query*: Object}

From the link we've created:

[Object, Object, Object, Object]

Will this make any difference?

Pls help me out with this issue.

Upvotes: 0

Views: 1281

Answers (1)

Dklaver
Dklaver

Reputation: 11

I realize this is an old post, and I'm not sure if anyone still needs help with this question, but I came across it after posting my own question. I have used this REDCap WDC multiple times over the past year to create custom Tableau WDC's. I know that this example is specifically for connecting to REDCap data, but the format/structure of the WDC is what I referred to the most when I was starting to build custom WDC's. Take a look at the code, you may find it useful.

(function() {
      var myConnector = tableau.makeConnector();
      // Define the schema
      //  myConnector.getSchema = function(schemaCallback){}
        myConnector.getSchema = function(schemaCallback) {
          var recordsInfo = [];
          $.ajax({
            url: JSON.parse(tableau.connectionData)['url'],
            type: "POST",
            data: {
              token: JSON.parse(tableau.connectionData)['token'],
              content: 'exportFieldNames',
              format: 'json',
              returnFormat: 'json',
              type: 'flat',
              rawOrLabelHeaders: 'raw',
              exportCheckboxLabel: 'true',
              exportSurveyFields: 'true',
              exportDataAccessGroups: 'true'
              },
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            success: function(resp){
                recordsInfo = resp;
                var recordSchema = [];
                recordsInfo.forEach(function(field){
                  recordSchema.push({
                    id: field.export_field_name,
                    alias: field.original_field_name,
                    dataType: tableau.dataTypeEnum.string
                  });
                });
                var redcapTable = {
                  id: "redcap",
                  alias: "custom redcap extract",
                  columns: recordSchema
                }
                schemaCallback([redcapTable]);
              }
            });
         };
      // Download the data
      myConnector.getData = function(table, doneCallback) {
        var tableData = [];
          $.ajax({
            url: JSON.parse(tableau.connectionData)['url'],
            type: "POST",
            data: {
              token: JSON.parse(tableau.connectionData)['token'],
              content: 'record',
              format: 'json',
              returnFormat: 'json',
              type: 'flat',
              rawOrLabelHeaders: 'raw',
              exportCheckboxLabel: 'true',
              exportSurveyFields: 'true',
              exportDataAccessGroups: 'true'
            },
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            success: function(resp){
            resp.forEach(function(record){
              tableData.push(record);
            });
            table.appendRows(tableData);
            doneCallback();
          }
        });
        }
      tableau.registerConnector(myConnector);
      $(document).ready(function (){
        $("#submitButton").click(function() {
            tableau.connectionData = JSON.stringify({
              'token': $("#token").val(),
              'url': $("#url").val()
            });
            tableau.connectionName = "REDCap Data";
            tableau.submit();
        });
      });
  })();

Upvotes: 1

Related Questions