-
-
Save gtaing1/7dd7b42b2a1492b44d9cec5cb4dbc707 to your computer and use it in GitHub Desktop.
Tableau JS API usage for Syncing Metric Names between datasources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************** | |
* | |
* Currently does not work due to http://community.tableau.com/thread/131070 | |
* | |
*********************************************************/ | |
var viz = tableau.VizManager.getVizs()[0] | |
var worksheets = viz.getWorkbook().getActiveSheet().getWorksheets() | |
var worksheetList = []; | |
for(var i=0;i<worksheets.length;i++){ | |
worksheets[i].getFiltersAsync().then(function(worksheetFilters){ | |
console.log(worksheetFilters) | |
var worksheetFilterValues = new Array(); | |
var worksheetFilterValuesMap = new Array(); | |
for(var j=0;j<worksheetFilters.length;j++){ | |
if(worksheetFilters[j].getFieldName()==="Measure Names"){ | |
worksheetFilterValues = worksheetFilters[j].getAppliedValues() | |
for(var k=0;k<worksheetFilterValues.length;k++){ | |
worksheetFilterValuesMap[worksheetFilterValues[k]['formattedValue']] = worksheetFilterValues[k]['value'] | |
} | |
worksheetList.push({ | |
"worksheet":worksheetFilters[j].getWorksheet(), | |
"Measure Names":worksheetFilterValuesMap | |
}) | |
} | |
} | |
}) | |
} | |
/********************************************************** | |
* | |
* Filters below use SuperStore dataset | |
* | |
*********************************************************/ | |
// Change based on "value" (ie. full name including datasource) | |
var _tmpArray = new Array(worksheetList[0]["Measure Names"]["Unit Price"]); | |
worksheetList[0]["worksheet"].applyFilterAsync("Measure Names", _tmpArray, tableau.FilterUpdateType.REPLACE) | |
.then(function(a){console.log(a)}) | |
.otherwise(function(e){console.log(e)}); | |
// Change based on "formattedValue" (ie. friendly name visable in filter dropdown) | |
var _tmpArray = new Array("Unit Price"); // This is to be sure I get it right | |
worksheetList[0]["worksheet"].applyFilterAsync("Measure Names", _tmpArray, tableau.FilterUpdateType.REPLACE) | |
.then(function(a){console.log(a)}) | |
.otherwise(function(e){console.log(e)}); | |
// This one works as it uses a different field | |
worksheetList[0]["worksheet"].applyFilterAsync("Continent", ["Africa","Asia"], tableau.FilterUpdateType.REPLACE) | |
.then(function(a){console.log(a)}) | |
.otherwise(function(e){console.log(e)}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment