Dynamic content block interactive filter on sys_user_group table

Srini22
Tera Contributor

I am trying to create an interactive filter using dynamic content blocks on the sys_user_group table to apply on a report based on a Database view that does an either or on a couple of group fields on the DB view. Unfortunately, the dropdown is not populating any values. Here is the code I have:

 

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

  <div id="groups_display">
    <select id='group_select' class="form-control widget-content select2" onchange="filter_group()">
      <option value="">Select a Group</option>
      <g:options choiceList="${jvar_groups}"
    </select>
  </div>

  <script>
      var dbh = new DashboardMessageHandler("filter_group");
      function filter_group() {
        var group = $j('#group_select').val();
        if (group) {
            dbh.publishFilter('u_audit_history_catalog_task_assignment_group', 'oldgroup_nameLIKE' + group);
        }
        else
        {
            dbh.removeFilter();
        }
    }
  </script>
</j:jelly>
1 ACCEPTED SOLUTION

Bhavya11
Kilo Patron

hi @Srini22 ,

i have made simple change on your above script and drop-down started showing up

 

  <g:evaluate var="jvar_groups" object="true" jelly="true">
 
below your script with modifying above line

 

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

  <div id="groups_display">
    <select id='group_select' class="form-control widget-content select2" onchange="filter_group()">
      <option value="">Select a Group</option>
      <g:options choiceList="${jvar_groups}"/>
    </select>
  </div>

  <script>
      var dbh = new DashboardMessageHandler("filter_group");
      function filter_group() {
        var group = $j('#group_select').val();
        if (group) {
            dbh.publishFilter('u_audit_history_catalog_task_assignment_group', 'oldgroup_nameLIKE' + group);
        }
        else
        {
            dbh.removeFilter();
        }
    }
  </script>
</j:jelly>

 

 

 

Please mark helpful & correct answer if it's really worthy for you.

 

 

Thanks,

BK

 

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,
BK

View solution in original post

4 REPLIES 4

Bhavya11
Kilo Patron

hi @Srini22 ,

i have made simple change on your above script and drop-down started showing up

 

  <g:evaluate var="jvar_groups" object="true" jelly="true">
 
below your script with modifying above line

 

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

  <div id="groups_display">
    <select id='group_select' class="form-control widget-content select2" onchange="filter_group()">
      <option value="">Select a Group</option>
      <g:options choiceList="${jvar_groups}"/>
    </select>
  </div>

  <script>
      var dbh = new DashboardMessageHandler("filter_group");
      function filter_group() {
        var group = $j('#group_select').val();
        if (group) {
            dbh.publishFilter('u_audit_history_catalog_task_assignment_group', 'oldgroup_nameLIKE' + group);
        }
        else
        {
            dbh.removeFilter();
        }
    }
  </script>
</j:jelly>

 

 

 

Please mark helpful & correct answer if it's really worthy for you.

 

 

Thanks,

BK

 

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,
BK

Srini22
Tera Contributor

Thank you so much! I missed that! The dropdown works now and I am able to filter based on the sys_ids. However, the filter behavior seems to be inconsistent. Sometimes the report is filtering correctly, while other time it is not, even when the filter is set correctly. I am having to keep toggling the "Follow Interactive Filter on/off. Please see screenshots when it is working/not working correctly. Any ideas why this may be happening?

Srini22
Tera Contributor

Here is the code I have:

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

  <div id="groups_display">
    <select id='group_select' class="form-control widget-content select2" onchange="filter_group()">
      <option value="">Select a Group</option>
      <g:options choiceList="${jvar_groups}" />
    </select>
  </div>

  <script>
      var dbh = new DashboardMessageHandler("filter_group");
      function filter_group() {
        var group = $j('#group_select').val();
        if (group) {
            dbh.publishFilter('u_audit_history_catalog_task_assignment_group', 'newgroup_sys_idLIKE' + group + '^ORoldgroup_sys_idLIKE' + group);          
        }
        else
        {
            dbh.removeFilter();
        }
    }
  </script>
</j:jelly>

Hi ,

Filter is displaying in dashboard, but there is no option to select act as a interactive filter. When i select one group in filter report is not following the interactive filter. Values not changing. I need modify anything in the code?