Interactive Filter setup to show specific choices for task type

alexbones
Tera Expert

Is there a way to setup interactive filters to only show specific task types? I only need to show a list of about 5 different task types. I have set up the interactive filter as a choice list, but I shows all task types in the drop down. I see there is an exclusions list, but that is adding a lot of exclusions to narrow down the scope to 5 types.

Thanks!

Alex

15 REPLIES 15

Arnoud Kooi
ServiceNow Employee

You need to update this and implement the method  

SNC.canvas.interactiveFilters.setDefaultValue


I have updated the code for a diffrent interactive filter here, hope that gets you on track!

 

Codeexample:

this https://github.com/arnoudkooi/snippets/blob/master/OR%20Interactive%20Filter%20Updated.xml

Hi @Arnoud Kooi  many thanks for coming back to us - so very much appreciated.

Here below is the code (of yours) that I am trying to use.

How would this look if fully updated as you you suggest so that this code fully works?

Many thanks.

<?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_tasktypes" object="true" jelly="true">
var tables = 'incident,problem,change_request,task'; 
var obj=[];
var gr= new GlideRecord('sys_db_object');
  gr.addEncodedQuery('super_classISNOTEMPTY^ORname=task^nameIN' + tables);
  gr.addOrderBy('name');
  gr.query();
  while(gr.next()){
    obj.push([gr.getValue('name'),gr.getValue('label')]);
  }
  obj;
</g:evaluate>
 
    <select id='filter_task_type' class='select2-search' onchange='filterTaskType()'>
        <option value="">All</option>
        <j:forEach var="jvar_tasktype" items="${jvar_tasktypes}"> 
            <option value="${jvar_tasktype[0]}">${jvar_tasktype[1]}</option>        
        </j:forEach>
    </select>   
 
    <script>
     var dbh = new DashboardMessageHandler("filter_tasktype");
     function filterTaskType(){
        var taskType = $j('#filter_task_type').val();
        if (taskType)
            dbh.publishFilter('task','sys_class_name=' + taskType);
        else
            dbh.removeFilter();
     }
     filterTaskType();
</script>
 
</j:jelly>

Arnoud Kooi
ServiceNow Employee

Analyze how that other Interactive Filter Implements the SNC.canvas.interactiveFilters.setDefaultValue and mimic that in this usecase.

 

I don't have the bandwidth now to dive into this.

@Arnoud Kooi  I unfortunately cannot get that script code working in Tokyo (the one above which filters Dashboard Widgets for 'Task Type', using the above script you shared about 5 years ago), even after trying to incorporate the above (SNC.canvas.interactiveFilters.setDefaultValue).

 

If you ever get a chance to look again and revisit the script so that it works, please do kindly share with me down the line.

 

I understand you may be busy and not have the bandwidth so I completely understand, but if you ever get a chance oneday, I would be greatly appreciative of your help Arnoud, kind sir.

 

Kindest Regards.

Arnoud Kooi
ServiceNow Employee

Please change the line

var dbh = new DashboardMessageHandler("filter_tasktype");

 

To

var dbh = new DashboardMessageHandler("filter_tasktype", function () {
	SNC.canvas.interactiveFilters.setDefaultValue({
		id: "filter_tasktype",
		filters: [{ table: "task", filter: "" }]
	}, false);
});

 You can adjust the default filter to your needs, I now left it empty but you could make it like:

"task_typeIN" + tables