Filter dashboard based on choice field

Akash Srivasta2
Tera Expert

Hi Team,

We have a dashboard where we have added a report (multi-pivot type), this report runs on demand task table.

 

We want to add a filter on the dashboard using which we can filter our reports, but the problem here is, we have a choice field which is available at Demand Table.

 

I am aware of interactive filters; we can use these to filter dashboard reports.... but we have a choice field here, also it is available on Demand table, I am not sure, how we can implement this.

 

Any suggestions would be a huge help.

 

3 REPLIES 3

Rampriya-S
Tera Guru
Tera Guru

rampriya_S_0-1739758716226.png

To set the filter field, you can dot-walk via the Parent and the respective choice field.

 

Please mark as helpful if the solution helps you.

 

 

Best,
Rampriya S

Hi rampriya,

Thanks for your response.

I have a field 'abc' which is a custom field and its available only on demand table.

The field 'Parent' which is a reference field is coming from task table. When I click on it, it shows the fields which are present at task table, so i am unable to select my field here.

Akash Srivasta2
Tera Expert

I have tried creating a content-block (Dynamic content), The field based on which I want to filter the reports is "

u_MyTestField". It is available on Demand (dmn_demand) form, and my report is created on demandTask (dmn_demand_task).
 
I can't figure it out why this content-block code is not working. Any suggestion here ?

Here is my script :-
 
<?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_status" object="true" jelly="true">
   
var statusArray=[];
var gr= new GlideRecord('sys_choice');
  gr.addEncodedQuery('nameSTARTSWITHdmn_demand^elementSTARTSWITHu_MyTestField');
<!--Query choice table to get the field values-->
  gr.query();
  while(gr.next()){
    statusArray.push([gr.getValue('value'),gr.getValue('label')]);
  }
 statusArray;
</g:evaluate>
 
<!--Creating DropDown field-->
<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 Logic -->
<script>
    var dashboardMessageHandler = new DashboardMessageHandler("filter_status");
    function filterStatus() {
        var status = $j('#filter_statuses').val();
        var filterOut = '';
        if (status) {
            filterOut = 'parent.u_MyTestField='+ status;
            var objFilter = {
                id: dashboardMessageHandler._unique_id,
                table: 'dmn_demand_task',  //Which table should I mention here ? I tried both demand and demandTask but it did not work.
                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>