cancel
Showing results for 
Search instead for 
Did you mean: 

Relative dates using Blox

ScheurK
9 - Travel Pro
9 - Travel Pro

Hi all,

 

I came across this article showing how change the date granularity for widgets using Blox:

https://support.sisense.com/kb/en/article/relative-date-filter-in-blox

 

However, in the Blox code it shows fixed entries (basically it forces current week, current month etc.):

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;

First question: does anyone still have the Blox template, I need access to the drive?

Second question is how do I change the Blox code, that this last part becomes dynamic? Ideally I would like this part to become dependent on the dashboard filter? 

Should I just remove the last two?

1 ACCEPTED SOLUTION

ScheurK
9 - Travel Pro
9 - Travel Pro

Use this:

https://support.sisense.com/kb/en/article/change-date-granularity-of-a-widget-using-blox

Or my code:

Action to be created: 

var widgets_data = [] //Add the item number of the widget, you can find this by opening the console in your dashboard (ctrl/cmd + f12 and entering prism.activeDashboard.widgets.$$widgets




//Add widgetsIDs that you would like to update

var widgets = ['<your o.id here','<second o.id here'] //Apply this action on widget ids, add extra widgets after comma



//for each widget id
widgets_data.forEach(changeDim)
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



}

function changeDim(item) {
if (payload.text == "Months") {


prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].field.id = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]_minutes";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.dim = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.title = "Months in ESTIMATED_DEPARTURE";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.level = "months";


} else if (payload.text == "Quarters") {


prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].field.id = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]_minutes";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.dim = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.title = "Quarters in ESTIMATED_DEPARTURE";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.level = "quarters";

} else if (payload.text == "Years") {


prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[0].field.id = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]_minutes";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[0].jaql.dim = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[0].jaql.title = "Years in ESTIMATED_DEPARTURE";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[0].jaql.level = "years";

} else if (payload.text == "Weeks") {


prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].field.id = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]_minutes";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.dim = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.title = "Weeks in ESTIMATED_DEPARTURE";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.level = "weeks";

}
}
 
Blox editor template: 
{
"type": "ActionSet",
"actions": [
{
"type": "<name of action>",
"text": "Years",
"title": "Years"
},
{
"type": "<name of action>",
"text": "Quarters",
"title": "Quarters"
},
{
"type": "<name of action>",
"text": "Months",
"title": "Months"
},
{
"type": "<name of action>",
"text": "Weeks",
"title": "Weeks"
}
]
}

View solution in original post

1 REPLY 1

ScheurK
9 - Travel Pro
9 - Travel Pro

Use this:

https://support.sisense.com/kb/en/article/change-date-granularity-of-a-widget-using-blox

Or my code:

Action to be created: 

var widgets_data = [] //Add the item number of the widget, you can find this by opening the console in your dashboard (ctrl/cmd + f12 and entering prism.activeDashboard.widgets.$$widgets




//Add widgetsIDs that you would like to update

var widgets = ['<your o.id here','<second o.id here'] //Apply this action on widget ids, add extra widgets after comma



//for each widget id
widgets_data.forEach(changeDim)
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



}

function changeDim(item) {
if (payload.text == "Months") {


prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].field.id = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]_minutes";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.dim = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.title = "Months in ESTIMATED_DEPARTURE";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.level = "months";


} else if (payload.text == "Quarters") {


prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].field.id = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]_minutes";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.dim = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.title = "Quarters in ESTIMATED_DEPARTURE";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.level = "quarters";

} else if (payload.text == "Years") {


prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[0].field.id = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]_minutes";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[0].jaql.dim = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[0].jaql.title = "Years in ESTIMATED_DEPARTURE";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[0].jaql.level = "years";

} else if (payload.text == "Weeks") {


prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].field.id = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]_minutes";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.dim = "[OPERATIONS_METRICS.ESTIMATED_DEPARTURE (Calendar)]";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.title = "Weeks in ESTIMATED_DEPARTURE";
prism.activeDashboard.widgets.$$widgets[item].metadata.panels[2].items[1].jaql.level = "weeks";

}
}
 
Blox editor template: 
{
"type": "ActionSet",
"actions": [
{
"type": "<name of action>",
"text": "Years",
"title": "Years"
},
{
"type": "<name of action>",
"text": "Quarters",
"title": "Quarters"
},
{
"type": "<name of action>",
"text": "Months",
"title": "Months"
},
{
"type": "<name of action>",
"text": "Weeks",
"title": "Weeks"
}
]
}