Forum Discussion
I have removed 'dashboard filter last 8 days' button and kept only 'Day Granularity' button. And updated your 'switchPanelItems' script to filter 2nd action ( last 8 days dashboard filter ) as well
Let me know if this is what you wanted
Blox changes :
Note : Please change the content under 'dateFilters' section to match with your dashboard date filter metadata
{
"type": "switchPanelItems",
"title": "Day Granularity",
"style": {
"width": "150px",
"background-color": "#a6a6a6"
},
"data": {
"actionDetails": [
{
"targetWidget": "628f953a600ec2002b8c2580",
"sourcePanel": "0",
"sourceItem": "0",
"destPanel": "0",
"destItem": "0",
"dimName": "Date"
},
{
"targetWidget": "628f900a600ec2002b8c2571",
"sourcePanel": "0",
"sourceItem": "0",
"destPanel": "0",
"destItem": "0",
"dimName": "Date"
}
],
"dateFilters": {
"dim": "[DIM DATE.Date (Calendar)]",
"title": "History",
"column": "Date",
"table": "DIM DATE",
"datatype": "datetime",
"level": "days",
"filter": {
"last": {
"count": 8,
"offset": 0
}
}
}
}
}
'switchPanelItems' custom script changes :
payload.data.actionDetails.forEach(function (a) {
var w = payload.widget.dashboard.widgets.$$widgets.filter(i => i.oid == a.targetWidget)[0];
w.metadata.panels[a.destPanel].items[a.destItem].jaql = JSON.parse(JSON.stringify(payload.widget.metadata.panels[a.sourcePanel].items[a.sourceItem].jaql));
if (typeof a.dimName == 'string') {
w.metadata.panels[a.destPanel].items[a.destItem].jaql.title = a.dimName;
};
w.changesMade();
w.refresh();
});
// Dashboard date filter
const datefilter = payload.data.dateFilters
prism.activeDashboard.filters.update(
{
'jaql': datefilter
},
{
'save': true,
'refresh': true,
'changesMade': true
}
)
HI keerthan
Sorry for slow response on this. Thank you for providing code.
I am having a problem with part of code which updates dashboard filter. Works great when you try to update date filter which is on the same level so if dashboard has week 20 of 2022 selected and I want to update to This week using count:1 and offset:0 then it works! updates existing filter.
In a different scenario though If I had dashboard filter at months level , lets say July-2022 selected and I want to updated to This week then new filter is created instead of updating existing one.
I think what would work is deleting the filter first by name ("title") as the code creates filter if it's not there.
Any chance you can add this update 🙂
Thanks,
Wojtek