DashboardMessageHandler publishes the filter, the report updates, but the filter is not applied

Greg Hoschar
Tera Contributor

I am working on a dynamic filter in San Diego release to forecast changes planned until the next business day. It adjusts for weekends and provides a checkbox for the user to specify there is an upcoming holiday within the forecast window.

GregHoschar_1-1674765146926.png

 

I used a Dynamic Content Block for the widget, named it Change Forecast, and entered the following code:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<div style="text-align: center;">
		<h1 style="text-align:center;" id="forecastDisplay">-</h1>
		<input style="vertical-align: top;" type="checkbox" id="forecastHoliday" name="forecastHoliday" onClick="updateForecastFilter()">
			<label style="vertical-align: bottom;" for="forecastHoliday">Holiday</label>
		</input>
	</div>

	<script>
		function updateForecastFilter(){
			var today = new Date();
			var dayOfWeek = today.getDay();
			var forecastDaysAhead = 1; // ends 1 day in the future
			if (dayOfWeek === 5) { // Friday
					forecastDaysAhead = 3; // end 3 days in the future to include the weekend
			}

			// check for holiday within the time range
			if($j("#forecastHoliday").is(":checked")) {
					if(dayOfWeek === 4) {
						forecastDaysAhead = 4; // Thursday through Sunday
					} else {
						forecastDaysAhead++; // add a day
					}
			}

			var forecastMessage = '1 day';
			if(forecastDaysAhead != 1) {
				forecastMessage = '' + forecastDaysAhead + ' days';
			}
			$j("#forecastDisplay").text(forecastMessage);
		
			var filter_message = {};
			filter_message.table = "change_request";
			filter_message.filter = "start_dateONToday@javascript&colon;gs.daysAgoStart(0)@javascript&colon;gs.daysAgoEnd(" + (1 - forecastDaysAhead) + ")";

			SNC.canvas.interactiveFilters.setDefaultValue({
					id: handlerID,
					filters: filter_message
			}, false);

			my_dashboardMessageHandler.publishFilter(filter_message.table,filter_message.filter);
		}

		var handlerID = "change_record_start_date_filter";
		var my_dashboardMessageHandler = new DashboardMessageHandler(handlerID);
		$j(document).ready(function() {
			updateForecastFilter();
		});  
	</script>
</j:jelly>

 

I created a dashboard with this widget, the "Debug homepage filters" widget (found at Interactive Filters > {Debug} > Debug homepage filters), the "Change Planned Start Date" widget (found at Interactive Filters > Date > Changed Planned Start Date - Single), and a simple report based on the change_request table called "Daily Ops (I&T) Change Forecast".

 

The "Daily Ops (I&T) Change Forecast" report has the "Follow interactive filter" and "Show when following filter" boxes checked.

GregHoschar_0-1674764247308.png

When the page first loads, the Change Forecast widget correctly displays "1 day" (Today is Thursday.) and the Debug Homepage filters widget displays: [{"filter":"start_dateONToday@javascript&colon;gs.daysAgoStart(0)@javascript&colon;gs.daysAgoEnd(0)","table":"change_request"}]

The "Daily Ops (I&T) Change Forecast" shows the interactive filter icon, but does not filter on Planned Start Date as expected.

GregHoschar_3-1674767246114.png

 

If I toggle the Holiday box, the Change Forecast updates to 4 days (Thursday through Sunday) and the Debug homepage filters widget displays: [[{"id":"change_record_start_date_filter","table":"change_request","filter":"start_dateONToday@javascript&colon;gs.daysAgoStart(0)@javascript&colon;gs.daysAgoEnd(-3)"}]]

The "Daily Ops (I&T) Change Forecast" report updates, but still has all the same same records, including those outside the specified time span.

 

Toggling the Holiday box off, it reverts to 1 day. The Debug homepage filters displays: [[{"id":"change_record_start_date_filter","table":"change_request","filter":"start_dateONToday@javascript&colon;gs.daysAgoStart(0)@javascript&colon;gs.daysAgoEnd(0)"}]]

The report updates, but still shows all the change records.

 

To verify that the report is responding to interactive filters, I go to the Change Planned Start Date widget and select "Today". The report updates, showing only the correct records that match today in the Planned start date field. The Debug homepage filters box displays both filters now: [[{"id":"change_record_start_date_filter","table":"change_request","filter":"start_dateONToday@javascript&colon;gs.daysAgoStart(0)@javascript&colon;gs.daysAgoEnd(0)"}],[{"table":"change_request","filter":"start_dateONToday@javascript&colon;gs.daysAgoStart(0)@javascript&colon;gs.daysAgoEnd(0)"}]]

 

The table and filter portions of both entries match exactly. For some reason the report is not responding to my filter. I am admin in the instances I am working in.

 

I have found references that indicate that I may need to toggle on "Act as interactive filter" for the Change Forecast widget, but it does not appear in my business instance, nor my PDI which is a fresh clean install with the APM module installed.

 

I have also seen detailed examples that do not mention the "Act as interactive filter" option. In the ServiceNow documentation (San Diego release) the only page that mentions this option is Make a report act as an interactive filter which does not pertain to Dynamic Content Blocks.

 

Why doesn't my Change Forecast widget filter the report? Any help is appreciated!

0 REPLIES 0