Modifying report dynamically on dashboard based on what tab is being viewed

Ahmad6
Giga Expert

Hi all,

I have a requirement from my colleague to make his life easier creating dashboards for new sites, by having a single graph change its data dynamically based on which dashboard it's in. We are more than happy to look at bar graphs stacked by location however some of our area managers may get overwhelmed by the data.

I have created the below script include, which uses the name of the dashboard to dynamically adjust the data being viewed in the dashboard, which allows us to place the same report in multiple dashboards:

var dashboard_filter = Class.create();
dashboard_filter.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	filterData :function(){
		//var user = gs.getUserID();
		var gr = new GlideRecord('sys_ui_navigator_history');
		gr.addEncodedQuery('user.DYNAMIC90d1921e5f510100a9ad2572f2b477fe^title=Dashboard^ORDERBYDESCsys_created_on');
		gr.query();
		if(gr.next()){
			//gs.log('--AE-- filtering dashboard on location ' + gr.description);
			return gr.description;
		} 
	},
	
	type: 'dashboard_filter'
});

Funnily enough, gs.getUserID() didn't affect the script however gs.log() broke it. The report is also very simple, and it can be placed on any dashboard as long as the dashboard name is the same as a location:

find_real_file.png

So now we will have fewer reports to manage, and we can duplicate an existing dashboard for every new site we bring onto ServiceNow and the data will automatically adjust. Now my colleague wants an even more interesting solution. He wants to give an area manager a single dashboard, but with tabs for each of his sites. Is there a way for me to tell exactly which tab of a dashboard is being viewed in a script include? My implementation relies on sys_ui_navigator_history to tell which dashboard is currently being viewed, but that doesn't mention when a tab is selected.

 

3 REPLIES 3

Adam Stout
ServiceNow Employee
ServiceNow Employee

You can't tell from the history you are checking, but I believe it is available on the client-side.  What I would do is create a custom interactive filter (placed near the top of the dashboard) that reads what is being viewed then if would add that info as an interactive filter for the reports being viewed.

Hi Adam,

 

As per the wiki: "You must have Performance Analytics premium to create new interactive filters." does this mean that I cannot implement your suggested solution without Performance Analytics?

gyedwab
Mega Guru

Adam's suggestion about using Interactive Filters is a great one -- I created one codelessly using Explore Analytics' dashboard to show a basic example of that approach:

https://my.exploreanalytics.com/pub/dashboard/6c9603b4c3264984addaee47195ab195