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

 

13 REPLIES 13

irismaessen
11 - Data Pipeline
11 - Data Pipeline

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

Milan
8 - Cloud Apps
8 - Cloud Apps

Hi @gowtham_sisense ,

I'm trying to implement this solution so I can have preset filters via dashboard urls for ease of navigation through multiple dasboards.

It appears that certain filters in the url will not pass through to the dashboard, particularly if the filter has "Include all" already preselected and default set on the dashboard.

Upon further investigation, if the filter of interest has an option selected, then the url will pass through the filter.

Is there anyway to enable the filter via url to pass through regardless of the data currently filtered on or not?

irismaessen
11 - Data Pipeline
11 - Data Pipeline

Hello Milan, 

(With the motto of better late than never)
Are you aware of the *regular* method of passing Dashboard filters?

You can always include the filter JAQL in the embed url, and set filters that way.
That article says to URL encode it, in my experience that is not always necessary (only if you have free text filters IME).
The filter JAQLs JSON.stringify retrieves using the above method is much bigger for me than the example in the article, and many of the components of the JAQL can be stripped (after some experimentation to check that the filter is still working, of course). But it *does* work.


try adding fil.jaql.filter.all = false

 

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]) })
	
	console.log(prism.activeDashboard.filters.$$items)
	
	prism.activeDashboard.filters.$$items.forEach(function(fil) {
		if (parameters.get(fil.jaql.title) !== undefined) 
		{
			fil.jaql.filter.all = false
			fil.jaql.filter.explicit = true
			fil.jaql.filter.userMultiSelect = true
			fil.jaql.filter.members = [parameters.get(fil.jaql.title)]
		}
	})
})

 

Milan
8 - Cloud Apps
8 - Cloud Apps

Another separate follow up q, how do you pass through a filter via the URL, for when a Date filter is set to "Last Month"?

 

Milan
8 - Cloud Apps
8 - Cloud Apps

Hello @Ophir_Buchman@gowtham_sisense  -- Any idea on the above?

ross_hendry
7 - Data Storage
7 - Data Storage

Is this possible on Periscope charts? When I try this, or the similar knowledge base article, `prism` is not a valid object to reference.

gyanianand
8 - Cloud Apps
8 - Cloud Apps

How do we pass multiple values for a filter in the url

Sushant_Cropin
7 - Data Storage
7 - Data Storage

I struggled a lot for the Dependent filters, here is a solution that works for me now. May save someone some time.


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(eachFilter) {
// For Indipendent Filter
if (eachFilter.isCascading == false)
{
if (parameters.get(eachFilter.jaql.column) !== undefined) 
{
eachFilter.jaql.filter.all = false
eachFilter.jaql.filter.explicit = true
eachFilter.jaql.filter.userMultiSelect = false
eachFilter.jaql.filter.members = [parameters.get(eachFilter.jaql.column)]
}
}
// For First Dependent Filter
else
{
if (parameters.get(eachFilter.levels[0].title) !== undefined) 
{
eachFilter.levels[0].filter.all = false
eachFilter.levels[0].filter.explicit = true
eachFilter.levels[0].filter.userMultiSelect = false
eachFilter.levels[0].filter.members = [parameters.get(eachFilter.levels[0].title)]
}
}
})
})