Create interactive filter to search on string type field

Prabhh
Mega Guru

Hello Team,

I am trying to add a filter for a string type field on the dashboard report table. I went through other community posts related to the same but didn't get much help on the code.

Please provide any example script to create a filter on string field.

Thank you in advance.

 

-Prabhh

1 ACCEPTED SOLUTION

Gabor10
Mega Guru

Hey everyone!

 

I had a really hard time finding any useful material on this topic as most of the links are dead.

 

The requirement I got from a user was that they should be able to filter their reports on their dashboards by the Short Description of the task.

 

I ended up creating a dynamic content block to act as an interactive filter. I hope somebody in the future finds this useful!

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
 
	
	  <style>	  		  

</style>
	
 <script>
	 
     var my_dashboardMessageHandler = new DashboardMessageHandler("FilterShortDescription");
    
    function publishFilter (searchTerm) {
        var filter_message = {};
        filter_message.id = "FilterShortDescription";
        filter_message.table = "task";
	 
	 if (searchTerm == ""){
	 clearFilter();
	 } 
	 else {
	 filter_message.filter = "short_descriptionSTARTSWITH"+ searchTerm;
	 }
        SNC.canvas.interactiveFilters.setDefaultValue({
                id: filter_message.id,
                filters: [filter_message]
            }, false);
        my_dashboardMessageHandler.publishFilter(filter_message.table, filter_message.filter);
    }
    
    function clearFilter() {
        var filter_message = {};
        filter_message.id = "FilterShortDescription";
        filter_message.table = "task";
        filter_message.filter = "";
        SNC.canvas.interactiveFilters.setDefaultValue({
                id: filter_message.id,
                filters: [filter_message]
            }, false);
        my_dashboardMessageHandler.removeFilter();
    }
 </script>   
	
            <input id="searchTerm" type="text" class="form-control" value="" onchange="publishFilter(this.value);"></input>
   
</j:jelly>

 

My end result looked something like this:

find_real_file.png

Ps.: I removed some parts of the sample script compared to what you can see on the screenshot. The sample script will only work with STARTSWITH search - so it should only act as a base which you can build upon.

You can add a couple of if conditions to make it "smarter", you may add your own CSS and HTML to the content block to make it work better with your own requirement. 

 

Have a nice day!

View solution in original post

43 REPLIES 43

Okay, so this is working for the Task table, but what if I wanted to expand this to additional tables (such as Interaction)?

 

Will this be able to check multiple tables with the same content block? (e.g. if I wanted it to filter the Incident Table and Interaction table)

How can we make it dynamic to search for Number, user_name, with a drop-down to select?

Hi,

 

Could you please tell me how you launch your script ?

 

kr,

Hello @Gabor10 ,

I've generated a report for the "incident_metric" table, and we need to retrieve the previous assignment group data. However, we must construct a filter on it in order to filter the previous  group's data, and the only method to do so is to create a filter on the value field. We tried your script, but it isn't working for me. Could you kindly look at it?

 

Script -

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
 
   
      <style>            

</style>
   
 <script>
     
     var my_dashboardMessageHandler = new DashboardMessageHandler("FilterShortDescription");
   
    function publishFilter (searchTerm) {
        var filter_message = {};
        filter_message.id = "FilterShortDescription";
        filter_message.table = "metric_instance";
   
     if (searchTerm == ""){
     clearFilter();
     }
     else {
     filter_message.filter = "valueSTARTSWITH"+ searchTerm;
     }
        SNC.canvas.interactiveFilters.setDefaultValue({
                id: filter_message.id,
                filters: [filter_message]
            }, false);
        my_dashboardMessageHandler.publishFilter(filter_message.table, filter_message.filter);
    }
   
    function clearFilter() {
        var filter_message = {};
        filter_message.id = "FilterShortDescription";
        filter_message.table = "metric_instance";
        filter_message.filter = "";
        SNC.canvas.interactiveFilters.setDefaultValue({
                id: filter_message.id,
                filters: [filter_message]
            }, false);
        my_dashboardMessageHandler.removeFilter();
    }
 </script>  
   
            <input id="searchTerm" type="text" class="form-control" value="" onchange="publishFilter(this.value);"></input>
   
</j:jelly>

 

 

Yogita11__0-1712075872552.jpeg

 

Hi @Gabor10 ,

 

I have same kind of requirement on kb_knowledge table. I just copied the code and changed the table name filter is working perfect. 

 

Thanks for the code.