Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to create custom intra active filter

lucky24
Tera Contributor

Hi Team,

I have created a dashboard and reports on the user table and I want to add interactive filters for the name field on the user table but there is no interactive field for the string type field.

I need to create a custom interactive filter for the name field on the user table so we can search any record from the user name.

I  want to include the condition active is true

I am not sure how to write code can someone help me?

Thanks

1 ACCEPTED SOLUTION

@lucky24 

Add 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 class="row" style="margin-left:10px; margin-right:10px">
	<div class="col-md-3"  style='width:330px'> 
		<p style="font-size:15px"><b>User Name</b></p>
		<input id='user_name' type = "text" onchange='filterUser()' ></input>
	</div>
	</div>
   <script>
     var dbh = new DashboardMessageHandler("filter_tasktype");
     function filterUser(){
        var userName = $j('#user_name').val();
		var filter_message = {};
         filter_message.id = "taskFilter"
         filter_message.table = "sys_user"
         
        if ((userName != '' )) {
            filter_message.filter = "nameLIKE"+userName;     
            SNC.canvas.interactiveFilters.setDefaultValue({
                id: filter_message.id,
                filters: [filter_message]
            }, false);
         dbh.publishFilter(filter_message.table, filter_message.filter);
        }
   else {
        filter_message.filter = "";     
            SNC.canvas.interactiveFilters.setDefaultValue({
                id: filter_message.id,
                filters: [filter_message]
            }, false);
            dbh.removeFilter();
        }
     }
</script>
</j:jelly>

 

Please mark correct/helpful if this helps you!

View solution in original post

7 REPLIES 7

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @lucky24 

 

Might be helpful

 

https://www.process.st/how-to/add-interactive-filters-in-servicenow-dashboard/

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Unique45
Mega Sage
Mega Sage

Hello @lucky24 ,

-Create dynamic content and add 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 class="row" style="margin-left:10px; margin-right:10px">
	<div class="col-md-3"  style='width:330px'> 
		<p style="font-size:15px"><b>User Name</b></p>
		<input id='user_name' type = "text" onchange='filterUser()' ></input>
	</div>
	</div>
   <script>
     var dbh = new DashboardMessageHandler("filter_tasktype");
     function filterUser(){
        var userName = $j('#user_name').val();
		var filter_message = {};
         filter_message.id = "taskFilter"
         filter_message.table = "sys_user"
         
        if ((userName != '' )) {
            filter_message.filter = "name="+userName;     
            SNC.canvas.interactiveFilters.setDefaultValue({
                id: filter_message.id,
                filters: [filter_message]
            }, false);
         dbh.publishFilter(filter_message.table, filter_message.filter);
        }
	else {
        filter_message.filter = "";     
            SNC.canvas.interactiveFilters.setDefaultValue({
                id: filter_message.id,
                filters: [filter_message]
            }, false);
            dbh.removeFilter();
        }
     }
</script>
</j:jelly>

 

 

 -In the dashboard, it will look like this:  

Unique45_0-1707138671170.png

 

 If you have any questions, please let me know.

 

Please mark correct/helpful if this helps you!

lucky24
Tera Contributor

Hi @Unique45 

Thanks for the reply I tried with your suggestion and It's working fine.

If I want to add contain in the user name condition where do I need to change in the above code

For example - If I write 3 words in the name it should show all names that include these 3 words,
Can I do like this?

Thanks

@lucky24 

Add 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 class="row" style="margin-left:10px; margin-right:10px">
	<div class="col-md-3"  style='width:330px'> 
		<p style="font-size:15px"><b>User Name</b></p>
		<input id='user_name' type = "text" onchange='filterUser()' ></input>
	</div>
	</div>
   <script>
     var dbh = new DashboardMessageHandler("filter_tasktype");
     function filterUser(){
        var userName = $j('#user_name').val();
		var filter_message = {};
         filter_message.id = "taskFilter"
         filter_message.table = "sys_user"
         
        if ((userName != '' )) {
            filter_message.filter = "nameLIKE"+userName;     
            SNC.canvas.interactiveFilters.setDefaultValue({
                id: filter_message.id,
                filters: [filter_message]
            }, false);
         dbh.publishFilter(filter_message.table, filter_message.filter);
        }
   else {
        filter_message.filter = "";     
            SNC.canvas.interactiveFilters.setDefaultValue({
                id: filter_message.id,
                filters: [filter_message]
            }, false);
            dbh.removeFilter();
        }
     }
</script>
</j:jelly>

 

Please mark correct/helpful if this helps you!