Forum Discussion

jacobgould's avatar
jacobgould
Data Storage
04-28-2022

Dashboard Custom advanced Filter

I'm attempting to create a custom(advanced script) date filter on a widget. My  base table has dates in the future for forecast planning, but I only want the widget to show results

 

from: "2020-01-03"  

to: "today". (I want getdate() or similar)

Is there a getdate() like function I can add into the code under advanced? 

 

 

1 Reply

Replies have been turned off for this discussion
  • tomlinton's avatar
    tomlinton
    Sisense Employee

    Hi - there is no "getDate()" functionality that I am aware of to be used here. Have you explored the "Time Frame" filter where you can set offsets? See the screenshot attached. Based on the date level you select, it will allow you to offset based on today's date. In my example, I am selecting yesterday. Would that work for you? The only downside is that this would only work if you are trying to do a rolling X number of days.

    There is definitely a way to set the anchor date like you have done and programmatically change the "to" date with a dashboard script. You would basically grab the filters on dashboard initialization and set the "to" date.

    Here is some code that I used in the dashboard script:

    dashboard.on('initialized',function(s,e) {
    	
    	let newFilter = e.dashboard.filters.item(0);
    	
    	let today = new Date()
    	let todayParsed = parsedDate = today.toISOString().substr(0,10)
    	
    	newFilter.jaql.filter.to = todayParsed
    	
    	e.dashboard.filters.update(newFilter,{refresh: true, save: true})
    	
    });