Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Dashboard Interactive Filter

ican
Tera Contributor

Use Case:

I have a dashboard with an Interactive Filter, Reports and Content Block in one tab, the content block is not following the interactive filter.

Is there any way I can get the interactive filter value to a widget?

 

For reference the Interactive Filter is custom, using UI Macro:

Custom Interactive Filter

 

Thanks.

3 REPLIES 3

Its_Azar
Tera Guru
Tera Guru

Hi there @ican 

 

you can pass the filter value to a widget using URL parameters or GlideRecord queries in the widget's server script.

 

  1. make sure that the interactive filter sets a URL parameter when a value is selected.
<!-- Example custom UI Macro -->
<g:macro>
  <select id="interactive_filter" onchange="updateFilter(this.value)">
    <!-- Options here -->
  </select>
  <script>
    function updateFilter(value) {
      var url = new URL(window.location);
      url.searchParams.set('filter_value', value);
      window.location = url;
    }
  </script>
</g:macro>

Now upadte widget to use filter val

 

(function() {
    // Get the filter value from the URL parameters
    var filterValue = gs.getSession().getRequestParameter('filter_value');

    // Use the filter value in your GlideRecord query
    var gr = new GlideRecord('your_table');
    if (filterValue) {
        gr.addQuery('your_filter_field', filterValue);
    }
    gr.query();
    
    var result = [];
    while (gr.next()) {
        result.push(gr.getDisplayValue());
    }
    
    data.result = result;
})();

 

If this helps kindly accept the respone thanks much. 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

ican
Tera Contributor

This is very helpful, but this will refresh the page upon selecting filter.

Is there a way wherein the page wont reload and just append parameter on URL?

 

Thanks.

ican
Tera Contributor

Also, I can't seem to get the URL parameter from dashboard widget.