
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ā11-21-2021 02:04 AM
Interactive filters?
Interactive Filters allow you to filter report widgets directly from a homepage or dashboard without modifying the reports. Servicenow comes up with many filter types but sometimes it requires applying a filter based on the catalog item/requested item variables and available interactive filters don't help.
Fortunately, as an administrator, you can create scripted filters and add them to the dashboard and homepages. With that being said, we are going to create our own scripted filter based on catalog item variables.
Pre-requisite
knowledge of Javascript/JellyScript - 6+ months
Knowledge of HTML - 6+ months
knowledge of Reports and filters - Basic
Catalog item with a variable which will be used for the scripted interactive filter.
What are we developing today?
I have a catalog item that contains a variable name Status of type select box. Three statuses are available as choices pending analysis, analysis in progress, and work in progress. I will be using that variable as a filter for our dashboard and upon selection of each status, a requested item list report will be filtered by that status.
Before diving into the development part, let's have a look at our end result
Solution
First, we will create a Dynamic Content page. Go to target dashboard, click on plus/add widget icon from the grey header, and select content blocks from the widget category dropdown. Select New Dynamic Content block from the list below and click Add button. A new widget will be added on the left content pane. you can click on click here hyperlink available in the body of the widget.
A new Dynamic Content Block form will open up. Our real scripting logic will go here. Please use the script below to create an HTML widget that contains the drop-down with all the choices for the status variable of the catalog item.
Please read the comments within the script carefully to understand the code and the required changes to make it work for you in your envrionment.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_status" object="true" jelly="true">
var statusArray=[];
<!-- Get choices of select box [status] and pass it to the widget UI -->
var gr= new GlideRecord('question_choice');
gr.addEncodedQuery('question=2eec46cc2f004d1023b0a55df699b65f'); <!-- replace the sys_id with the sys_id of your variable. -->
gr.addOrderBy('name');
gr.query();
while(gr.next()){
statusArray.push([gr.getValue('value'),gr.getValue('text')]);
}
statusArray;
</g:evaluate>
<select id='filter_statuses' class='select2-search' onchange='filterStatus()'>
<option value="">All</option>
<j:forEach var="jvar_state" items="${jvar_status}">
<option value="${jvar_state[0]}">${jvar_state[1]}</option>
</j:forEach>
</select>
<script>
var dbh = new DashboardMessageHandler("filter_status");
function filterStatus(){
var status = $j('#filter_statuses').val();
if (status)
dbh.publishFilter('sc_req_item', 'cat_item=c45927732f3b3c1023b0a55df699b636^variables.2eec46cc2f004d1023b0a55df699b65f=' + status); <!-- change the cat_item sys_id and variable.sys_id with actual sys id of catalog item and target variable. -->
else
dbh.removeFilter();
}
filterStatus();
</script>
</j:jelly>
After making the suggested changes in the script comments, save the form.
Open the dashboard and if the interactive filter doesn't appear then click on the add widget icon and select widget category as Content block and search for your content block created in the above step by name.
Hover over the report widget title bar and select the settings cog to open the widget configuration. Select checkbox "Follow interactive filters" & "Show when following interactive filters".
Congrats, You are done!
Changing the filter will now filter down the list of records based on the selection.
Reference
Please mark it as helpful, bookmark it for future reference and provide feedback or ask questions in the comment box below.
- 15,463 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
hi

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
test
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Very good nformation and aplication, only I have a question, why when I enter the dashboard where the filter is, I choose an option, but the data in the graph does not change?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Maury, the Last step in the process is the answer to your question. Have you tried to set the Follow Interactive filter in the report widget configurations? Please refer the last screenshot above.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Muhammad, I have tried the All steps mentioned above but at last step when I click on Edit widget, I am unable to get Interactivity option. Please let me know the solution for that.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hey @Bindhu1 - That option will appear when you edit the target report widget.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Can it be possible to select specific custom interactive filter should work of specific report in one dashboard and not for all ?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Amit Naik1 ,
To the best of my knowledge, I believe that is not possible. All the reports following interactive filters will be affected by all the available interactive filters in the dashboard.
Regards,
Muhammad
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
script tag code is not working in Tokyo environment.
I have updated the code kindly review
<script>
var dashboardMessageHandler = new DashboardMessageHandler("filter_status");
function filterStatus(){
var status = $j('#filter_statuses').val();
var filterOut = '';
if (status)
{
filterOut = 'variables.2eec46cc2f004d1023b0a55df699b65f=' + status; <!-- change the cat_item sys_id and variable.sys_id with actual sys id of catalog item and target variable. -->
var objFilter = {
id : 'custom_department_list_filter',
table : 'sc_req_item',
filter : filterOut
};
SNC.canvas.interactiveFilters.setDefaultValue({
id : objFilter.id,
filters : [objFilter]
}, false);
dashboardMessageHandler.publishFilter(objFilter.table, objFilter.filter);
}else{
dashboardMessageHandler.removeFilter();
}
}
filterStatus();
</script>
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hey Amit, your code fixed it, however, the "All" button doesn't reset the filters back to normal. Does anyone have a solution?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
To create a custom interactive filter based on catalog item variables in ServiceNow, you can follow these steps:
Navigate to the Catalog Items section in the Service Catalog.
Open the catalog item for which you want to create a custom interactive filter.
Click on the "Variables" tab and select the variable that you want to use for the filter.
Click on the "Variable Attributes" related link.
In the Variable Attributes page, click on the "UI Properties" related link.
In the UI Properties section, set the "Variable Type" to "Choice".
In the "Choices" field, enter the values that you want to use for the filter options. Each value should be separated by a comma.......
Save the variable and publish the catalog item.
Navigate to the "Filters" section in the Service Catalog.
Click on the "New" button to create a new filter.
In the "Name" field, enter a name for the filter.
In the "Table" field, select the catalog item table (sc_cat_item).
In the "Advanced" section, click on the "Add Filter Condition" button.
In the "Field" dropdown, select the variable that you want to use for the filter.
In the "Operator" dropdown, select "is".
In the "Value" field, enter the first value that you entered in the "Choices" field.
Click on the "Add Or Condition" button.
Repeat steps 14-17 for each value that you entered in the "Choices" field.
Click on the "Save" button to save the filter.
Test the filter by navigating to the Service Catalog and selecting the filter from the "Filter" dropdown.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This should solve resetting the filter when "All" option is chosen:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_status" object="true" jelly="true">
var statusArray=[];
<!-- Get choices of select box [status] and pass it to the widget UI -->
var gr= new GlideRecord('question_choice');
gr.addEncodedQuery('question=0956e00f1b29e51054eca752b24bcb36'); <!-- replace the sys_id with the sys_id of your variable. -->
gr.addOrderBy('name');
gr.query();
while(gr.next()){
statusArray.push([gr.getValue('value'),gr.getValue('text')]);
}
statusArray;
</g:evaluate>
<select id='filter_statuses' class='select2-search' onchange='filterStatus()'>
<option value="">All</option>
<j:forEach var="jvar_state" items="${jvar_status}">
<option value="${jvar_state[0]}">${jvar_state[1]}</option>
</j:forEach>
</select>
<script>
var dashboardMessageHandler = new DashboardMessageHandler("filter_status");
function filterStatus() {
var status = $j('#filter_statuses').val();
var filterOut = '';
if (status) {
filterOut = 'variables.0956e00f1b29e51054eca752b24bcb36=' + status; <!-- change the cat_item sys_id and variable.sys_id with actual sys id of catalog item and target variable. -->
var objFilter = {
id: dashboardMessageHandler._unique_id,
table: 'sc_req_item',
filter: filterOut
};
SNC.canvas.interactiveFilters.setDefaultValue({
id: objFilter.id,
filters: [objFilter]
}, false);
dashboardMessageHandler.publishFilter(objFilter.table, objFilter.filter);
} else {
SNC.canvas.interactiveFilters.removeDefaultValue(dashboardMessageHandler._unique_id, false);
dashboardMessageHandler.removeFilter();
}
}
filterStatus();
</script>
</j:jelly>
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How to apply it for multiple tables. for example, on sc_req_item and task_sla
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is it possible to apply this on dashboard where reports created on multiple tables such as sc_req_item, task_sla, sc_req_metrics, etc
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
There are two issues occurring:
When I refresh the page in the report, it displays all the records initially. However, after making changes in the "Follow Interactive Filter" & "Show when Following Filter" fields, such as unchecking them and then refreshing again, the filter works as expected.
Additionally, I am unable to find an option to navigate to the next set of records.
Could you confirm if this behavior is expected?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
hello I have reference field on RITM now I want a filter on the dashboard on the basic all the RITM report are visible let suppose there is 1 catalog item in this we have a variable which is reference to incident table so for this I create the reports and dashboard now I want a intractive filter for the reference variable, if user select incident on the basic all the reports of RITM will change can any one help me to solve this problem
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you for the great tutorial! In my case, the variable is a reference to department. I want to give the user a way to filter on these departments, however I can't seem to get that query to work. I'm building the list using the cmn_department table and setting the select option value to the sys_id, but the query:
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
So hepfull than you so much.
How can we modify the code to have the possibility to have muti select choice on the dynamic content please?
Thank you š
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Saurav Bhardwa2 - this is a result of not calling `SNC.canvas.interactiveFilters.setDefaultValue()` first before `publishFilter()`.
Here's an official example that shows how to do this: https://docs.servicenow.com/bundle/xanadu-now-intelligence/page/use/dashboards/reference/r_CustomPub...
@Bongio - this isn't too hard, where you are creating the `select` html element, you want to add the attribute `multiple` to the <select> tag. Then you would need to update the filter function so that it fetches all the values and builds a list, and then change the query to use `IN` instead of `=` such as `subcategoryINdb2,sql server,oracle`
Review this for the query operators:
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@DJones4
Regarding the below would you mind sharing me your code on how you got the filter on Reference variable working to display the departments please? I would like to see how you used the 'IN' rather than the '=' and where. I am trying to do the same with a reference variable looking up cmn_locations. Right now the Dynamic Content simply displays All and not the referenced options.
In my case, the variable is a reference to department. I want to give the user a way to filter on these departments, however I can't seem to get that query to work. I'm building the list using the cmn_department table and setting the select option value to the sys_id, but the query:
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Why, when I refresh the page, do I have to deactivate and save and activate again the follow interactive filter so that the filter works fine?