2 Replies Latest reply on Mar 16, 2018 8:16 AM by Matthew Ary

    Applying a Filter on a Secondary Data Source from JavaScript API

    Matthew Ary

      I'm trying to figure out how to apply filters to a dashboard that contains multiple worksheets, some of which have secondary data sources. I found this in the KB Applying a Filter on a Secondary Data Source from JavaScript API | Tableau Software but I have a few issues with it.

      1. It only shows only an example for a rangeFilter.

      2. I need to make it work with a categorical filter.

      3. It doesn't tell me how to get the data source name or what it looks like.

      4. When using the JavaScript API to get the datasource name for a filter that I want to apply, and then when using that name as shown in the KB example but on a categorical filter, it always gives me the error code "invalidFilterFieldName" for my efforts.

      5. This particular feature is missing from the actual JavaScript API documentation.

      6. I'm doubting this feature even exists, and I'm now just screwing around with the API to see if it works at all.

      7. The DataSource names that the JavaScript API is giving me look like this "federated.07srrt40o0w5vw1bs30zk0zqssuf" which don't match the formatting seen when you get names in the REST API.

       

      So here is my question. How do you use the JavaScript API to apply filters to worksheets with secondary data sources? Am I getting the data source name correctly or, if not what is the right way to get it? What should a data source name look like?

      Why is none of this in the JavaScript API documentation and only in a tiny KB article?

       

      Thanks,

       

      Matthew Ary

      ----------------------------------------

      Update:

       

      I worked on this problem all last week. Then after about an hour after making this forum post, I started thinking. Every example of using hierarchy with filters has opening and closing brackets in the example. Brackets were also present in KB example. Before, I interpreted the brackets to indicate that the entire string it enclosed (including the brackets) were to be substituted by my values. So I was doing something like this (which is wrong):

      worksheet.applyFilterAsync('federated.07srrt40o0w5vw1bs30zk0zqssuf.geography', 'US', tableau.FilterUpdateType.REPLACE)

       

      Instead of this (which is right):

      worksheet.applyFilterAsync('[federated.07srrt40o0w5vw1bs30zk0zqssuf].[geography]', 'US', tableau.FilterUpdateType.REPLACE)

       

      Once I applied the brackets, applying filters to a secondary data source worked.

       

      I'm leaving this post here to help others. Also if Tableau can update the JavaScript API with this information and its particulars that would be helpful too.

       

      Message was edited by: Matthew Ary