The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Custom Interactive filter: Dynamic content block on List collector field

Maloy Banerjee
Mega Expert

Hi All,

 

I have created a custom interactive filter for the list collector field named - "Strategies" in Demand Table. The filter will be used for the report created on the database view of demand table (u_demand_sla).

Below is the Dynamic content block I created:

 

<?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 obj=[];
var gr= new GlideRecord('strategic_objective');
gr.addActiveQuery();
gr.addOrderBy('title');
gr.query();
while(gr.next()){
obj.push(gr.title.getValue());
//obj.push([gr.getDisplayValue('title')]);
}
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('u_demand_sla','dmn_strategic_objectivesISNOTEMPTY');
else
dbh.removeFilter();
}
filterTaskType();
</script>

</j:jelly>

 

Currently the outcome for this is below:

 find_real_file.png

The drop down is appearing with empty selectable options. Also, if I try to select the empty options, the filter doesn't gets applied to the reports.

So I need 2 help:

1. What is wrong in my code, because of which the values are not visible.

2. What change is needed in my code to make the filter work.

 

 

Thanks & Regards,

Maloy Banerjee

1 ACCEPTED SOLUTION

Adam Stout
ServiceNow Employee
ServiceNow Employee

Why won't a standard filter work?

For a custom filter, what I do is build a choice list then let jelly do the hard work:

Build Choice:

var cl = new GlideChoiceList();
var gr = new GlideAggregate('sys_user_group');
gr.groupBy('sys_id');
gr.groupBy('name');
gr.addEncodedQuery('active=true');
gr.orderBy('name');
gr.query();
while(gr.next())
{
    cl.add(gr.getValue('sys_id'), gr.getDisplayValue());
}

Create select using choice:

<div id="${jvar_uuid}_display" style="display: none">
    <select id='${jvar_uuid}_select' class="form-control widget-content select2">
        <option value="">All</option>
        <g:options choiceList='${jvar_cl}' />
    </select>
</div>

View solution in original post

5 REPLIES 5

Adam Stout
ServiceNow Employee
ServiceNow Employee

Why won't a standard filter work?

For a custom filter, what I do is build a choice list then let jelly do the hard work:

Build Choice:

var cl = new GlideChoiceList();
var gr = new GlideAggregate('sys_user_group');
gr.groupBy('sys_id');
gr.groupBy('name');
gr.addEncodedQuery('active=true');
gr.orderBy('name');
gr.query();
while(gr.next())
{
    cl.add(gr.getValue('sys_id'), gr.getDisplayValue());
}

Create select using choice:

<div id="${jvar_uuid}_display" style="display: none">
    <select id='${jvar_uuid}_select' class="form-control widget-content select2">
        <option value="">All</option>
        <g:options choiceList='${jvar_cl}' />
    </select>
</div>

Adam,

I'm not experienced with jelly at all. I'm trying to build a custom interactive filter for a glide list type of custom field on the business application table. I tried to piece something together based on the conversation above using Maloy's format with your suggestion. It's not working at all. Would you mind helping me out with the dynamic content block below?

<?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_l3s" object="false" jelly="true">
var cl = new GlideChoiceList();
var gr = new GlideRecord('apm_application_category');
gr.orderBy('name');
gr.query();
while(gr.next())
{
cl.add(gr.getValue('sys_id'), gr.getDisplayValue());
}
</g:evaluate>

<div id="l3_display" style="display: none">
<select id='l3_select' class="form-control widget-content select2">
<option value="">All</option>
<g:options choiceList='${jvar_l3s}' />
</select>
</div>

<script>
var dbh = new DashboardMessageHandler("filter_l3");
function filterl3(){
var l3 = $j('#l3_select').val();
if (l3)
dbh.publishFilter('cmdb_ci_business_app','u_secondary_technologyLIKEl3');
else
dbh.removeFilter();
}
filterl3();
</script>
</j:jelly>

I'm not sure of what else is wrong, but this line should probably use the l3 variable.

dbh.publishFilter('cmdb_ci_business_app','u_secondary_technologyLIKEl3');

should be

dbh.publishFilter('cmdb_ci_business_app','u_secondary_technologyLIKE' + l3);

Add the interactive filter debugger to see what is actually happening.  If you have a JavaScript error, you may see that in the browser console.

 

jmcagod
Kilo Guru

@Maloy Banerjee - were you able to make this work?