Skip to content
Everything Servicenow
Everything Servicenow

Master the Now Platform — One Article at a Time

  • How-Tos
  • Scripting
  • Integration
Everything Servicenow

Master the Now Platform — One Article at a Time

Custom Interactive filter based on Catalog item variables

Posted on December 4, 2025December 6, 2025 By devsharjeel
find_real_file.png

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 

find_real_file.png

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. 

find_real_file.png

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.

find_real_file.pngHover 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”.

find_real_file.pngCongrats, You are done!  

Changing the filter will now filter down the list of records based on the selection. 

Reference

https://docs.servicenow.com/bundle/rome-now-intelligence/page/use/dashboards/concept/c_CustomPublish…
Scripting Uncategorized

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

©2025 Everything Servicenow | WordPress Theme by SuperbThemes