Forum Discussion
Hi jplefka ,
One alternative is to write a similar script in 'initialized' event of dashboard.
For example:
dashboard.on('initialized', function (se, ev) {
currentYear = new Date().getFullYear().toString()
datefilter = se.filters.$$items.find(el=>el.jaql.title == 'Date')
datefilter.jaql.filter = {
"explicit": true,
"multiSelection": true,
"members": [
currentYear
]
}
var filterOptions = {
save: true,
refresh: true,
}
se.filters.update(datefilter, filterOptions)
});
-Hari
Thanks, this works great for changing the date filter, however it keeps clearing out preset background and locked filters that I have, is there a way I can stop that from happening?
- harikm00708-12-2022Data Warehouse
jplefka If you have background filter set, try below script:
dashboard.on('initialized', function (se, ev) { currentYear = new Date().getFullYear().toString() filter = se.filters.$$items.find(el=>el.jaql.title == 'Date') backgroundfilter = filter.jaql.filter.filter defaultValue = 'West' filter.jaql.filter = { "explicit": true, "multiSelection": true, "filter":backgroundfilter, "members": [ currentYear ] } var filterOptions = { save: true, refresh: true, } se.filters.update(filter, filterOptions) });
-Hari
- jplefka08-12-2022Data Storage
I don't have background filters set on this current filter, what is happening is the se.filters.update(datefilter, filterOptions) command is altering all my other filters, and any with backround filters set are gettin gmessed up. I just need to code to touch filter "Date" and thats it
- harikm00708-12-2022Data Warehouse
Since we added below line of code, it should filter to only 'Date' filter.
filter = se.filters.$$items.find(el=>el.jaql.title == 'Date')
Are you using same script as above? If possible, can you share the script you are using, so that I can try to replicate the issue.
-Hari