<script custom-tag="" type="application/ld+json">{"@context":"https://schema.org","@type":"TechArticle","headline":"Custom Interactive Filters basics","image":"http://support.servicenow.com/29f1d2661baf6010cafa53d8624bcb43.iix","author":{"name":"ServiceNow Support","url":"http://support.servicenow.com/now"},"keywords":"ServiceNow, NowSupport public Knowledge Base articles, Support and Troubleshooting,KB0827667,","wordcount":"564","publisher":"ServiceNow","url":"https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0827667","datePublished":"2020-06-09","dateCreated":"2020-06-08","dateModified":"2024-04-08","description":"<h2>Custom Interactive Filters basics</h2><br/><div style=\"overflow-x:auto\"><p><span style=\"font-size: 10pt; font-family: verdana, geneva;\">A custom interactive filter can be used to filter multiple R","articleBody":"<h2>Custom Interactive Filters basics</h2><br/><div style=\"overflow-x:auto\"><p><span style=\"font-size: 10pt; font-family: verdana, geneva;\">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.</span></p>\r\n<p><span style=\"font-size: 10pt; font-family: verdana, geneva;\">Please keep in mind the following points creating a custom interactive filter:</span></p>\r\n<ul style=\"list-style-position: inside;\"><li style=\"font-size: 10pt; font-family: Calibri, sans-serif; color: black;\"><span style=\"font-size: 10pt; font-family: verdana, geneva;\">If the custom interactive filter is planned to be used only for one table, <strong><em>DashboardMessageHandler.publishFilter()</em></strong> function can be used.</span><br /></li><li style=\"font-size: 10pt; font-family: Calibri, sans-serif; color: black;\"><span style=\"font-family: verdana, geneva; font-size: 10pt;\">If the custom interactive filter is planned to be applied to multiple tables, <strong><em><span style=\"color: black;\">DashboardMessageHandler.publishMessage()</span></em></strong> function can be used. </span></li><li style=\"font-size: 10pt;\"><span style=\"font-family: verdana, geneva; font-size: 10pt;\">Before publishing an interactive filter call to <strong><em>SNC.canvas.interactiveFilters.setDefaultValue(</em>)</strong> function is mandatory starting from Orlando​.</span></li><li style=\"font-size: 10pt; color: black;\"><span style=\"font-family: verdana, geneva; font-size: 10pt;\">The call to function <strong><em>SNC.canvas.interactiveFilters.removeDefaultValue()</em></strong> or <strong><em>DashboardMessageHandler.removeFilter()</em></strong> is mandatory before resetting the filter.</span></li></ul>\r\n<p style=\"margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;\"><br /></p>\r\n<p style=\"margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;\"><span style=\"font-size: 10pt; font-family: verdana, geneva;\">ServiceNow <a title=\"Docs\" href=\"https://docs.servicenow.com/bundle/orlando-performance-analytics-and-reporting/page/use/dashboards/reference/r_CustomPublisherExample.html\" rel=\"nofollow\">Docs</a> site has an example regarding using the interactive filter for a single table. Since the API <strong><em><span style=\"color: black;\">DashboardMessageHandler.publishMessage()</span></em></strong> is not documented, sometimes we see implementations using <strong><em>DashboardMessageHandler.publishFilter()</em></strong> multiple times.</span></p>\r\n<ol style=\"list-style-position: inside;\"><li style=\"font-size: 10pt; font-family: Calibri, sans-serif;\"><span style=\"font-size: 10pt; font-family: verdana, geneva;\">Create two <strong>DashboardMessageHandler</strong> instance and call the <span style=\"font-family: verdana, geneva;\"><strong><em>publishFilter()</em></strong></span> method two times. All the report widget following interactive filter refreshes 2 times.</span></li><li style=\"font-size: 10pt; font-family: Calibri, sans-serif;\"><span style=\"font-size: 10pt; font-family: verdana, geneva;\">Some times when it is necessary to use the filter for more than 2 tables, an array is created and in a loop, <strong>N</strong> <strong>DashboardMessageHandler</strong> instances are constructed.  Since the <strong>publishFilter()</strong> method will be called <strong>N</strong> times, that will refresh all the reports following interactive filter <strong>N</strong> times which will most probably cause performance issues.</span></li></ol>\r\n<h1><span style=\"font-size: 12pt;\"><strong><span style=\"font-family: verdana, geneva;\">How to apply Custom Interactive Filter to multiple tables</span></strong></span></h1>\r\n<p style=\"margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: Calibri, sans-serif;\"><span style=\"font-family: verdana, geneva; font-size: 10pt;\">The example below filters the Report using <strong>incident</strong> and <strong>problem</strong> tables by assignment group using a custom interactive filter. Ex:</span></p>\r\n<ul style=\"list-style-position: inside;\"><li style=\"font-size: 10pt; font-family: Calibri, sans-serif;\"><span style=\"font-family: verdana, geneva; font-size: 10pt;\">Number of open Problems</span></li><li style=\"font-size: 10pt; font-family: Calibri, sans-serif;\"><span style=\"font-size: 10pt;\"><span style=\"font-family: verdana, geneva;\">Number of open Incidents</span> </span></li></ul>\r\n<p><span style=\"font-size: 10pt;\"><span style=\"font-family: verdana, geneva;\"><strong><em><span style=\"color: black;\">DashboardMessageHandler.publishMessage() </span></em></strong></span><span style=\"font-family: verdana, geneva;\">accepts multiple filters as an array, one can just construct the filter array properly then create only one instance of <strong>DashboardMessageHandler</strong> and then call <strong>DashboardMessageHandler.publishMessage([filters])</strong>. This will refresh the widget only one time and is more performant compared to calling <strong><em>DashboardMessageHandler.publishFilter()</em></strong> multiple times. </span></span></p>\r\n<p><br /></p>\r\n<h2><span style=\"font-size: 10pt;\"><span style=\"font-size: 12pt;\"><strong><span style=\"font-family: &#39;Times New Roman&#39;, serif;\">Example:<br /></span></strong></span><span style=\"font-family: &#39;Times New Roman&#39;, serif;\"><br />&lt;?xml version&#61;&#34;1.0&#34; encoding&#61;&#34;utf-8&#34; ?&gt;<br />&lt;j:jelly trim&#61;&#34;false&#34; xmlns:j&#61;&#34;jelly:core&#34; xmlns:g&#61;&#34;glide&#34; xmlns:j2&#61;&#34;null&#34; xmlns:g2&#61;&#34;null&#34;&gt;<br />&lt;script&gt;<br />var my_dashboardMessageHandler &#61; new DashboardMessageHandler(&#34;my_unique_id&#34;);<br /><br />function publishMultipleFilter() {<br />&lt;!-- Mutliple filters can be passed as an array --&gt;<br />var finalFilter &#61; [{&#34;table&#34;:&#34;incident&#34;,&#34;filter&#34;:&#34;assignment_group&#61;6fcd3b573b331300ad3cc9bb34efc447&#34;}, {&#34;table&#34;:&#34;problem&#34;,&#34;filter&#34;:&#34;assignment_group&#61;6fcd3b573b331300ad3cc9bb34efc447&#34;}];<br />&lt;!-- call setDefaultValue first --&gt;<br />SNC.canvas.interactiveFilters.setDefaultValue({<br />id: my_dashboardMessageHandler._unique_id,<br />filters: finalFilter,<br />}, false);<br /><br />&lt;!-- then call Publishmessage to publish filters--&gt;<br />my_dashboardMessageHandler.publishMessage(finalFilter);<br />}<br /><br />function clearFilter() {<br />SNC.canvas.interactiveFilters.removeDefaultValue(my_dashboardMessageHandler._unique_id, false);<br />my_dashboardMessageHandler.removeFilter();<br />}<br />&lt;/script&gt; <br /><br />Example of a filter that filters incident and problem table where assign_ment group is Problem solving &lt;br/&gt;<br />&lt;input id&#61;&#34;allTasks&#34; type&#61;&#34;button&#34; value&#61;&#34;All&#34; onclick&#61;&#34;clearFilter();&#34; /&gt;<br />&lt;input id&#61;&#34;onlyMine&#34; type&#61;&#34;button&#34; value&#61;&#34;Assignment group is [Problem solving]&#34; onclick&#61;&#34;publishMultipleFilter();&#34; /&gt;<br /><br />&lt;/j:jelly&gt;</span></span></h2></div>"}</script>
  Loading...