How to create a Filter using a Custom Content Block to filter on a catalog item variable (type ref)

MartinKirwan
Tera Contributor

Looking for some help here.

I'm trying to create a Filter on a Dashboard that uses a catalog item variable (User name) to show only the RITM in the list report which has the same user record.
This is a proof of concept and once I get this working I'll be able to implement properly.

In the Content Block record I've got my jelly script as shown.

Using a Glide Record to populate an array with the results of the query, Creating the dropdown and iterating over the array to populate that.
Then (and I think this might be the part I've got wrong) I'm trying to filter using the selected status and the variable sysID from the sc_req_item table.

filterOut = 'variables.c62da65bc3cc9e10e1f41533e4013188=' + status;
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">
<g:evaluate var="jvar_status" object="true" jelly="true">
    var statusArray = [];
    var gr = new GlideRecord('sys_user'); 
    gr.addEncodedQuery('active=true^user_nameSTARTSWITHa'); 
    gr.addOrderBy('user_name');
    gr.query();
    
    while (gr.next()) {
        
        statusArray.push([gr.getValue('sys_id'), gr.getValue('name')]); 
    }
    
    statusArray;
</g:evaluate>

<select id='filter_statuses' class='select2-search' onchange='filterStatus()'>
    <option value="">All</option>
    <j:forEach var="jvar_state" items="${jvar_status}">
        <option value="${jvar_state[0]}">${jvar_state[1]}</option>
    </j:forEach>
</select>
<script>
var dashboardMessageHandler = new DashboardMessageHandler("filter_status");
console.log('DashboardMessageHandler initialized with ID: ' + dashboardMessageHandler._unique_id);

function filterStatus() {
    var status = $j('#filter_statuses').val();
    console.log('Selected status: ' + status);
    var filterOut = '';
    if (status) {
        filterOut = 'variables.c62da65bc3cc9e10e1f41533e4013188=' + status; 
        console.log('Filter applied: ' + filterOut); 
        var objFilter = {
            id: dashboardMessageHandler._unique_id,
            table: 'sc_req_item',
            filter: filterOut
        };

        SNC.canvas.interactiveFilters.setDefaultValue({
            id: objFilter.id,
            filters: [objFilter]
        }, false);
        dashboardMessageHandler.publishFilter(objFilter.table, objFilter.filter);
    } else {
        
        SNC.canvas.interactiveFilters.removeDefaultValue(dashboardMessageHandler._unique_id, false);
        dashboardMessageHandler.removeFilter();
    }
}
filterStatus();
</script>
</j:jelly>

I've got a RITM with the user selected but when I select that user the RITM is not displayed.

Can anyone give me a steer? 
Thanks!

3 REPLIES 3

MartinKirwan
Tera Contributor

no filter applied - RITM showingno filter applied - RITM showingFilter applied - no RITM - consoleFilter applied - no RITM - console

MartinKirwan
Tera Contributor

sysIDs used are correct 🙂

MartinKirwan
Tera Contributor

I changed the getValue('sys_id') to getValue('name') as I realised that the query worked with the display value rather than the sys_id and it worked!
DOH!

statusArray.push([gr.getValue('sys_id'), gr.getValue('name')]);