Relative Date Filter in Blox

Part 1: Preparation And Setup
- Download the BloX Template Here
- Import the Template into BloX (tutorial here)
- Create an action called "RelativeDate"
- Add the code below to the action and save it.
if (payload.text == "Year" ) {
prism.activeDashboard.filters.$$items[0].jaql.level = "years";
prism.activeDashboard.filters.$$items[0].jaql.filter.last.count = 1;
prism.activeDashboard.filters.$$items[0].jaql.filter.last.offset = 0;
} else if (payload.text == "Qtr" ) {
prism.activeDashboard.filters.$$items[0].jaql.level = "quarters";
prism.activeDashboard.filters.$$items[0].jaql.filter.last.count = 1;
prism.activeDashboard.filters.$$items[0].jaql.filter.last.offset = 0;
} else if (payload.text == "Month" ) {
prism.activeDashboard.filters.$$items[0].jaql.level = "months";
prism.activeDashboard.filters.$$items[0].jaql.filter.last.count = 1;
prism.activeDashboard.filters.$$items[0].jaql.filter.last.offset = 0;
} else if (payload.text == "LastMonth" ) {
prism.activeDashboard.filters.$$items[0].jaql.level = "months";
prism.activeDashboard.filters.$$items[0].jaql.filter.last.count = 1;
prism.activeDashboard.filters.$$items[0].jaql.filter.last.offset = 1;
} else if (payload.text == "Week" ) {
prism.activeDashboard.filters.$$items[0].jaql.level = "weeks";
prism.activeDashboard.filters.$$items[0].jaql.filter.last.count = 1;
prism.activeDashboard.filters.$$items[0].jaql.filter.last.offset = 0;
}
//Add widgetsIDs that you would like to update
var widgets = ['5efb8c3ad957252878a2bb7d','5efb8c5dd957252878a2bb7f'] //Apply this action on widget ids
//for each widget id
widgets.forEach(myfunction)
function myfunction (item)
{
var widgetfindid = prism.activeDashboard.widgets.$$widgets.find(w => w.oid === item)
widgetfindid.changesMade() //apply changes to Mongo
widgetfindid.refresh() //refresh the widget
}
CONFIGURATION STEP A: DEFINING FILTER
Add a filer on a Date Dimension using the “Time Frame” option.
STEP B: CONFIGURING YOUR ACTION
The action has this format:
This code is in the blox “Editor” section. Add the items you want to filter on.
"type": "ActionSet",
"actions": [
{
"type": "RelativeDate",
"text": "Week",
"title": "Current Week"
},
{
"type": "RelativeDate",
"text": "Month",
"title": "Current Month"
},
This code is in the action. Add the “if” portion to correspond with the “ActionSet”.
if (payload.text == "Year" ) {
prism.activeDashboard.filters.$$items[0].jaql.level = "years";
prism.activeDashboard.filters.$$items[0].jaql.filter.last.count = 1;
prism.activeDashboard.filters.$$items[0].jaql.filter.last.offset = 0;
} else if
--- See the code in the action
Apply and enjoy!
Updated 02-16-2024
intapiuser
Admin
Joined December 15, 2022