javascript - Creating Tableau WDC from associative array -
i creating tableau web data connector described in getting started guide here.
i have implemented similar solution previous data basic associative array, having trouble current api call.
i make api call external web service returns json similar 1 listed below (simplified version)(comment added clarity , not part of original code).
{ "status": true, "employee": { "id": 123 }, "company": { "id": 123 }, "job": { "id": 123, "job_workflows": [{ "id": 1, "name": "start", "action_value_entered": "start" }, { "id": 2, "name": "date", "action_value_entered": "2017-09-11" }, { "id": 3, "name": "crew", "action_value_entered": "crew 3" }, **comment** - 17 other unique fields - omitted brevity ] } }
for requirements, need create new column each of json job_workflows display data in tableau. i.e.
- column 1 header = start
- column 1 value = start
- column 2 header = date complete
- column 2 value = 2017-09-11
etc.
my tableau javascript file looks below:
(function () { var myconnector = tableau.makeconnector(); myconnector.init = function(initcallback) { initcallback(); tableau.submit(); }; myconnector.getschema = function (schemacallback) { var cols = [ { id : "start", alias : "start", datatype: tableau.datatypeenum.string }, { id : "date", alias : "date", datatype: tableau.datatypeenum.datetime }, { id : "crew", alias : "crew", datatype: tableau.datatypeenum.string } ]; var tableinfo = { id : "mydata", alias : "my data", columns : cols }; schemacallback([tableinfo]); }; myconnector.getdata = function (table, donecallback) { $.getjson("http://some/api/call/data.php", function(response) { var resp = response; // response json described above var tabledata = []; // iterate on json object (var = 0, len = feat.length; < len; i++) { // not working tabledata.push({ "start": resp.job.job_workflows[i].action_value_entered, "date": resp.job.job_workflows[i].action_value_entered, "crew": resp.job.job_workflows[i].action_value_entered }); } table.appendrows(tabledata); donecallback(); }); }; tableau.registerconnector(myconnector); })();
how iterate on json job_workflow , assign each action_value_entered id in getschema() function? current version hangs , no values returned. no error or warnings thrown.
Comments
Post a Comment