Forum Discussion

Lisha's avatar
Lisha
Cloud Apps
10-04-2022
Solved

Dashboard Filter

Hi,

I had a requirement to set my Dashboard date filter to have end date as today and this should be the default filter. (eg. 1 Jan 2022 to today)

I found below script that does the job of setting today as end date dynamically.

https://community.sisense.com/t5/build-analytics/dashboard-custom-advanced-filter/m-p/3117/highlight/true#M742

Now, if I set this as default filter manually today (1 Jan 2022 to 4 Oct 2022); it will still be the default filter tomorrow unless I manually set it to tomorrow's date. I want the default filter to be reset dynamically as well. It should always be <start date> to today.

Is there a way to achieve this ?

  • Hi Lisha ,

    Try this script along with existing dashboard script.

    dashboard.on('filterschanged', function (se, ev) {
    
    	if(ev.items[0].jaql.title == 'As Of Month')
    	{
    		let today = new Date()
    		let todayParsed = parsedDate = today.toISOString().substr(0,10)
    	
    		ev.items[0].jaql.filter.to = todayParsed
    	
    	}
    });
    

    -Hari

4 Replies

Replies have been turned off for this discussion
  • harikm007's avatar
    harikm007
    Data Warehouse

    Hi Lisha ,

    Try this script along with existing dashboard script.

    dashboard.on('filterschanged', function (se, ev) {
    
    	if(ev.items[0].jaql.title == 'As Of Month')
    	{
    		let today = new Date()
    		let todayParsed = parsedDate = today.toISOString().substr(0,10)
    	
    		ev.items[0].jaql.filter.to = todayParsed
    	
    	}
    });
    

    -Hari

    • Lisha's avatar
      Lisha
      Cloud Apps

      Hi harikm007 

      This script is not working as expected. As you can see the date was set to today which is correct.

      However, on click of restore my default filters it goes back to the default filter that was set manually earlier. The default filter was not reset to have to date as today.

       

       

      • harikm007's avatar
        harikm007
        Data Warehouse

        Did you replace 'As Of Month' in above script with title of your filter ('Date')? ( I missed this to mention in above post).