cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a BloX action on Widget or Dashboard Load

jplefka
7 - Data Storage
7 - Data Storage

I have a BloX action that triggers a change of filter to the latest date available.  The Blox widget itself is loading the date that it needs to use.   Is there a way I can execute this BloX Widgets Action when the widget or dashbaord loads or renders?  

8 REPLIES 8

harikm007
13 - Data Warehouse
13 - Data Warehouse

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? 

harikm007
13 - Data Warehouse
13 - Data 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

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

harikm007
13 - Data Warehouse
13 - Data 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

Since 'm using older data in my DEV environment the latest date i have is from June so i'm hard coding it for now

 

dashboard.on('initialized', function (se, ev) {

currentYear = '06/01/2022'
datefilter = se.filters.$$items.find(el=>el.jaql.title == 'As Of Month')

datefilter.jaql.filter = {
"explicit": true,
"multiSelection": false,
"members": [currentYear]
}

var filterOptions = {
save: true,
refresh: true,
}

se.filters.update(datefilter, filterOptions)
});

harikm007
13 - Data Warehouse
13 - Data Warehouse

This is interesting. I tried the same code and it works for me (I have 2 more dashboard filters with background filter and locked filter). Are you using any other dashboard script? Also can I ask screenshot of filter panel after executing this script? 

-Hari

No this is the only script i'm using, here is the before and afterjplefka_0-1660325226592.png