A custom interactive filter can be used to filter multiple Reports using different tables. There are two different APIs to publish an interactive filter for a single table or multiple tables.
Please keep in mind the following points creating a custom interactive filter:
- If the custom interactive filter is planned to be used only for one table, DashboardMessageHandler.publishFilter() function can be used.
- If the custom interactive filter is planned to be applied to multiple tables, DashboardMessageHandler.publishMessage() function can be used.
- Before publishing an interactive filter call to SNC.canvas.interactiveFilters.setDefaultValue() function is mandatory starting from Orlando.
- The call to function SNC.canvas.interactiveFilters.removeDefaultValue() or DashboardMessageHandler.removeFilter() is mandatory before resetting the filter.
The ServiceNow Docs site used to have only an example of using the interactive filter for a single table. The API DashboardMessageHandler.publishMessage() is also documented. You can find similar information in Docs.
- Create two DashboardMessageHandler instance and call the publishFilter() method two times. All the report widget following interactive filter refreshes 2 times.
- Some times when it is necessary to use the filter for more than 2 tables, an array is created and in a loop, N DashboardMessageHandler instances are constructed. Since the publishFilter() method will be called N times, that will refresh all the reports following interactive filter N times which will most probably cause performance issues.
How to apply Custom Interactive Filter to multiple tables
The example below filters the Report using incident and problem tables by assignment group using a custom interactive filter. Ex:
- Number of open Problems
- Number of open Incidents
DashboardMessageHandler.publishMessage() accepts multiple filters as an array, one can just construct the filter array properly then create only one instance of DashboardMessageHandler and then call DashboardMessageHandler.publishMessage([filters]). This will refresh the widget only one time and is more performant compared to calling DashboardMessageHandler.publishFilter() multiple times.