Applying Multiple DashboardMessageHandler Filters from a single click

alondc
Mega Contributor

Hi Community, 


I have a pretty simple problem, I have reports from 3 tables (incident, sc_task, change_request) in a single dashboard. I want to create a dyanmic content block that will allow the user to select a customer, and then use that tenant's ID to publish a filter to all of the reports to only show info (for the INC's, tasks, and changes) for that customer. There is virtually zero documentation I have been able to find on how to deal with multiple mydashboardmessagehandlers other than vague allusions that it can be done. I have had mixed results with the content below so far. The first published filter works great, the second does not get applied at all, and the 3rd gets applied but the reports must be manually refreshed in the dashboard to display the updated value. 

 

NOTE: I have tried moving the order of the 3 publish filters around in the setfilter function. The issue persist with regards to where the argument is they all work if they are first, don't work if they are second, and work with a manual report refresh if they are 3rd. 

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<script>
 var inc_dashboardMessageHandler = new DashboardMessageHandler("");
 var task_dashboardMessageHandler = new DashboardMessageHandler("");
 var chg_dashboardMessageHandler = new DashboardMessageHandler("");
 function setFilter()
	{
		var tenant_id = document.getElementById('tenant_id').value;
		inc_dashboardMessageHandler.publishFilter('sc_task', 'request_item.u_tenantLIKE' + tenant_id');
 		chg_dashboardMessageHandler.publishFilter('change_request', 'u_affected_accountsLIKE' + tenant_id); <!-- Unclear why but this middle filter never works   -->
		task_dashboardMessageHandler.publishFilter('sc_task', 'request_item.u_tenantLIKE' + tenant_id);	<!-- This filter is applied but the report does not auto-refresh with the new info   -->
	} 
function StopFilter()
	{
		task_dashboardMessageHandler.removeFilter();
		inc_dashboardMessageHandler.removeFilter();
		chg_dashboardMessageHandler.removeFilter();
	} 
</script>
<h1>Select the specific customer whose work you want to view.</h1> <br/> 
<p><strong> NOTE: This search will only display customers that are available in Service Now. </strong></p><br/> 
<g:ui_reference name="tenant_id" id="tenant_id" table="customer_account" selected="tenant_id" />
	<h2> Click on the Apply Filter once you have selected the customer </h2><br/>
<input id="all_tenants" type="button" value="Remove Filter" onclick="StopFilter();" />
<input id="only_selected_tenant" type="button" value="Apply Filter" onclick="setFilter()" />

</j:jelly>
1 ACCEPTED SOLUTION

Adam Stout
ServiceNow Employee
ServiceNow Employee

Try:

DMH.publishMessage([{"table": "incident", "filter": "state=1"}, {"table": "incident_task", "filter": "parent.state=1"}]);

I'm not sure if these query strings work, but hopefully, you get the point.

View solution in original post

14 REPLIES 14

alondc
Mega Contributor

Hi again, 


After taking a break and looking at the code again I realized that I didn't assign unique ID's to each dashboard message handler variables. Once I assigned each of them a unique value they were all applied correctly to the dashboard, so the application of the filters issue has been fixed in the code below. 

I am still hitting the same issue that others have seen with multiple publishfilters not triggering an autorefresh for dashboard reports after the first report has been updated.

 

I've been looking for ways to place a delay between the publication of each filter or to trigger a refresh or every report contained in the dashboard after all of the filters have been published. Any advice would be much appreciated 

 

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<script>
 var inc_dashboardMessageHandler = new DashboardMessageHandler("id1");
 var task_dashboardMessageHandler = new DashboardMessageHandler("id2");
 var chg_dashboardMessageHandler = new DashboardMessageHandler("id3");
 function setFilter()
	{
		var tenant_id = document.getElementById('tenant_id').value;
		inc_dashboardMessageHandler.publishFilter('incident', 'u_affected_accountsLIKE' + tenant_id);
		task_dashboardMessageHandler.publishFilter('sc_task', 'request_item.u_tenant.sys_id=' + tenant_id);
		chg_dashboardMessageHandler.publishFilter('change_request', 'u_affected_accountsLIKE' + tenant_id); 
	} 
function StopFilter()
	{
		task_dashboardMessageHandler.removeFilter();
		inc_dashboardMessageHandler.removeFilter();
		chg_dashboardMessageHandler.removeFilter();
	} 
</script>
<h1>Select the specific customer whose work you want to view.</h1> <br/> 
<p><strong> NOTE: This search will only display customers that are available in the Service Now. </strong></p><br/> 
<g:ui_reference name="tenant_id" id="tenant_id" table="customer_account" selected="tenant_id" />
	<h2> Click on the Apply Filter once you have selected the customer </h2><br/>
<input id="all_tenants" type="button" value="Remove Filter" onclick="StopFilter();" />
<input id="only_selected_tenant" type="button" value="Apply Filter" onclick="setFilter()" />

</j:jelly>

Adam Stout
ServiceNow Employee
ServiceNow Employee

Why wouldn't use a normal interactive filter?  Why does it need to be custom?

alondc
Mega Contributor

Because we don't have the performance analytics plugin on our instances

Adam Stout
ServiceNow Employee
ServiceNow Employee

You need a license to use interactive filters (custom or not).  While the UI won't let you create new filters, if you create a custom interactive filter, you would still (most likely) be out of compliance.