How to apply Dynamic Content block filters to multiple reports in Dashboard

shaik11
Tera Expert

Hi,

 

My requirement is to apply custom created Content block filter for "task type" field in Task table. I need to apply the filter for multiple reports which belongs to same task table in dashboard. In the task type filter, I need to display only 9 choices, On the of selection of task type option reports should display the particular records list and tickets count in the dashboard.

I have used the below script, but it is not working.

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">
<g:evaluate var="jvar_tasktypes" object="true" jelly="true">
var tables = 'incident,problem,change_request,incident_task,problem_task,change_task,sc_task,sc_req_item';
 
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 filter_message = {};
filter_message.id = "filter_tasktype";
filter_message.table = "task";
 
        var taskType = $j('#filter_task_type').val();
filter_message.filter = fltr;
SNC.canvas.interactiveFilters.setDefaultValue({
id: filter_message.id,
filters: [filter_message]
}, false);
        if (taskType!=''){
            dbh.publishFilter('task','sys_class_name=' + taskType);
}
        else{
 
            dbh.removeFilter();
}
     }
    filterTaskType();
</script>
 
</j:jelly>
 
Please provide script inputs, at what point I have done wrong.
shaik11_0-1686073996453.png

Thanks & Regards,

Reshma

1 REPLY 1

simonezini
Mega Sage

Hi @shaik11 ,

I know this is an old topic but I've found a solution here: Re: Dynamic content block with two filters - ServiceNow Community

Hope this helps!


 

Regards,

Simone