cancel
Showing results for 
Search instead for 
Did you mean: 

Dashboard - Passing Filter Values Using URL Parameters

Ophir_Buchman
Sisense Team Member
Sisense Team Member

A customer may want to pass a filter value using the URL (as a parameter). A common case could be when an external system launches a dashboard and wants it to default to a specific value.

The following script allows you to parse the parameters received in the URL and apply them to the dashboard filters.

Steps:

1. Apply the following script to your dashboard:

dashboard.on('initialized', function(widget) {
// Get Parameters
urlParameters = window.location.href.substring(window.location.href.indexOf('?')+1).split('&')

// Parse Parameters
parameters = new Map();
urlParameters.forEach(function(param) { parameters.set(param.split('=')[0],param.split('=')[1]) })

prism.activeDashboard.filters.$$items.forEach(function(fil) {
if (parameters.get(fil.jaql.title) !== undefined) {
fil.jaql.filter.explicit = true
fil.jaql.filter.userMultiSelect = true
fil.jaql.filter.members = [parameters.get(fil.jaql.title)]
}
})
})

2. Acquire the URL of your dashboard
(e.g. https://test.sisense.com/app/main#/dashboards/62a...ae1)

3. Add parameters (align with filter names):
https://test.sisense.com/app/main#/dashboards/62a...ae1
?Region123=US&CountryName=Iowa

4. Refresh the dashboard and watch your filters pane:

Ophir_Buchman_0-1654805158204.png

 

5 REPLIES 5

irismaessen
10 - ETL
10 - ETL

That looks pretty useful and a lot more readable than passing the filter JAQL in the url -- but does this replace the filter JAQL method of setting filters in newer Sisense versions or is this an additional possibility?

Iris

Hi @irismaessen - This is a different approach to the problem...

Hey Ophir,

That's great, I'll have to investigate if this doesn't work better for us in some cases.

Thank you for the information!

@Ophir_Buchman How would you write the filter in the URL if there are spaces in the filter name? For example say instead of Region123, the name was Region 123?

Similarly, how would you add the filter value if there are spaces in the value? 

gowtham_sisense
Sisense Team Member
Sisense Team Member

[EDIT] If you have any spaces or other special characters in the filter member names that get encoded when passed in the URL, use the following dashboard script: 

 

dashboard.on('initialized', function(widget) {
	// Get Parameters
	urlParameters = decodeURIComponent(window.location.href.substring(window.location.href.indexOf('?')+1)).split('&');
	// Parse Parameters
	parameters = new Map();
	urlParameters.forEach(function(param) { parameters.set(param.split('=')[0],param.split('=')[1]) })
	
	prism.activeDashboard.filters.$$items.forEach(function(fil) {
		if (parameters.get(fil.jaql.title) !== undefined) 
		{
			fil.jaql.filter.explicit = true
			fil.jaql.filter.userMultiSelect = true
			fil.jaql.filter.members = [parameters.get(fil.jaql.title)]
		}
	})
})

 

Stay Healthy,
Gowtham Senthilkumar