cancel
Showing results for 
Search instead for 
Did you mean: 
ILLIA
Sisense Team Member
Sisense Team Member

Disclaimer: Please note that this blog post contains one possible custom workaround solution for users with similar use cases. We cannot guarantee that the custom code solution described in this post will work in every scenario or with every Sisense software version. As such, we strongly advise users to test solutions in their environment before deploying them to ensure that the solutions proffered function as desired in their environment. For the avoidance of doubt, the content of this blog post is provided to you "as-is" and without warranty of any kind, express, implied, or otherwise, including without limitation any warranty of security and or fitness for a particular purpose. The workaround solution described in this post incorporates custom coding, which is outside the Sisense product development environment and is, therefore, not covered by Sisense warranty and support services.

Modify Date filters using EmbedSDK to keep the original filter ID

There are cases when you need to modify the existing date filter level but as Sisense considers it as a new filter that should be added as a separate one - some issues could be faced. Currently, the most common way to do this is to remove old date filters and apply new date filters which are the same except for level. But sometimes you need to exclude date filters from your widgets and the reference to it is based on filter ID which is not the same once you remove filters and then add new filters.
This behavior happens because the EmbedSDK dashboard object contains filters without IDs so you can modify filters by referring to dimension only (or dimension + level only for date filters). 

Example:

 

const changeLevel = async (level) => {
       let dateFilters = window.dashboard.filters.filter(f => f.jaql.datatype === 'datetime')
       await window.sisenseFrame.dashboard.removeFilters(dateFilters, true)
     dateFilters.forEach(f => {
         f.jaql.level = level
     })
      await window.sisenseFrame.dashboard.applyFilters(dateFilters, true)
  }

 


This function updates date filters on the dashboard to set the level passed as an argument. 
It removes current filters and then sets updated filters. 
window.dashboard is a dashboard object returned on dashboardloaded event.
In this example, 2 indicator widgets exclude respective date filters, once you execute this function - both filters will be present on widgets and the results might be unexpected:

ILLIA_0-1711622179130.png


Each widget should use its filter and exclude another one, but currently, both of the filters are used on them causing N/A results.
Solution:

 

 

const changeLevelWA = async (level) => {
       let currentFilters = await fetch(`/api/v1/dashboards/${dashboardId}?fields=filters`)
       currentFilters = await currentFilters.json()
       let dateFilters = currentFilters.filters.filter(f => f.jaql.datatype === 'datetime')
       await window.sisenseFrame.dashboard.removeFilters(dateFilters, true)
     dateFilters.forEach(f => {
         f.jaql.level = level
     })
      await window.sisenseFrame.dashboard.applyFilters(dateFilters, true)
  }

 

 

This example does the same logic, but instead of using the dashboard object returned from the dashboardloaded event, it sends an API request to get dashboard filters directly. The difference is that API response filters contain an instanceID parameter which is used on widgets to identify which filter should be excluded.
As a result, we create new filters using the same instanceID, and relevant filters remain excluded: 

ILLIA_1-1711622555864.png


Each widget uses its relevant filter after the update.

 

Rate this article:
Version history
Last update:
‎03-28-2024 07:42 AM
Updated by:
Contributors