Custom Interactive Filter not getting applied on Report if I reload Dashboard

Rahul Dalal
Tera Contributor

Hi, I have create a Custom interactive filter which is getting used to filter on a glide list variable referencing to cmn_location table.

Issue - The filter runs perfectly fine  on the report on the Dashboard and if i add the report for first time. But if i just reload the tab and apply that filter again. Then report just shows all values.

Adding code and screenshot

 

RahulDalal_1-1751395172891.png

 

 

<?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 regions = [];
        var grLoc = new GlideRecord('cmn_location');
        grLoc.addQuery('u_location_type', 'Region');
        grLoc.orderBy('name');
        grLoc.query();
        while (grLoc.next()) {
            regions.push({
                sys_id: grLoc.sys_id.toString(),
                name: grLoc.name.toString()
            });
        }
        gs.log('Regions: ' + JSON.stringify(regions)); // Added logging for server-side debug
        regions; // This makes the 'regions' array available to jvar_tasktypes
    </g:evaluate>

    <div style="padding: 10px; border: 1px solid #ccc; background-color: #f9f9f9; border-radius: 5px;">
        <label for="outage_location_region" style="font-weight: bold; margin-bottom: 5px; display: block;">Select Impacted Region(s):</label>
        <select id='outage_location_region' class='select2-search' onchange='outageLocationFilter()' style="width: 100%; padding: 5px; border: 1px solid #ddd; border-radius: 3px;">
            <option value="">-- All Regions --</option>
            <j:forEach var="jvar_tasktype" items="${jvar_tasktypes}">
                <option value="${jvar_tasktype.sys_id}">${jvar_tasktype.name}</option>
            </j:forEach>
        </select>
    </div>

    <script>
        // Ensure jQuery is loaded before using $j
        if (typeof jQuery == 'undefined') {
            console.warn("jQuery is not loaded. DashboardMessageHandler and $j might not work.");
        }

        // DashboardMessageHandler for interactive filters
        var dbh_location = new DashboardMessageHandler("outage_locations");

        function outageLocationFilter() {
            var location_sysID = $j('#outage_location_region').val(); // Get selected value using jQuery
            console.log('Selected Region SysID: ' + location_sysID); // Added logging

            if (location_sysID) {
                dbh_location.publishFilter('cmdb_ci_outage', 'u_impacted_regionISNOTEMPTY^u_impacted_regionLIKE' + location_sysID);
            } else {
                dbh_location.removeFilter();
            }
        }

        // Call the filter function once on page load to set the initial state
        document.addEventListener('DOMContentLoaded', function() {
            console.log('Page loaded, calling outageLocationFilter'); // Added logging
            outageLocationFilter();
        });
    </script>
</j:jelly>


 

0 REPLIES 0