Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

How to set Dynamic Default Value for Month Interactive Filter in ServiceNow Dashboard

Tejas Adhalrao
Kilo Sage

I have a ServiceNow dashboard with two interactive filters: Month and Year. The Month filter is a choice list, as shown in the attached screenshot.

Currently, the Month filter has a static default value, for example January.

My requirement is to make the default value dynamic based on the current month:

  • If the current month is September, the default Month should be August
  • If the current month is October, the default Month should be September
  • If the current month is January, the default Month should be December and the Year should automatically be the previous year
  • In general, the default should always be current month - 1

 

Thanks!

TejasAdhalrao_0-1786606346917.png

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@Tejas Adhalrao 

not possible with the OOTB config

You can try to use custom interactive filters

Custom Interactive Filters basics 

Custom interactive filters (DashboardMessageHandler.publishFilter()) don't work with multiple tables 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

lauri457
Kilo Patron

The problem is that dashboards have user preferences that will store settings history for the user. It would be simple to recreate the dashboard in ui builder and apply the values to the filters but I'm assuming technical dashboard will still do the above so even if you change the widget metadata the user prefs will override the default.

 

So you'd probably have to anyway edit user preferences from a scheduled job or similar.

 

User preference [sys_user_preference] for a dashboard will have the name: "com.snc.par.dashboards.ui.preferences.[dashboard_sysid]". The schema itself is easily understood, below is a user pref for a dashboard with one tab and a single filter on incident.category applied

{
	"filters": {
		"375d66ff93664f100898b4897bba103a": {
			"parFilters": [{
				"filterId": "mss70iff",
				"values": ["inquiry"],
				"origin": "FILTER_COMPONENT",
				"apply_to": ["incident.category"],
				"label": "Filter",
				"source": {
					"payload": {
						"field": "category",
						"fieldType": "choice",
						"table": "incident",
						"primaryKey": "sys_id"
					},
					"type": "table"
				},
				"type": "choice",
				"order": 0,
				"include_unmatched_or_empty": false
			}],
			"encodedQueries": { "incident": "category=inquiry" }
		},
		"top_layout": {
			"parFilters": [],
			"encodedQueries": {}
		}
	}
}