Setting up custom dynamic filters with predefined filter for record list in UI Builder

PDawg
Tera Expert

Recently, I have encountered a small issue with how record list component does not work with dynamic filters I configured for Data Visualizations as per below article: 

https://www.servicenow.com/community/developer-blog/set-up-interactive-filter-on-ui-builder-for-data...

 

Here are some steps to reproduce to make this work this and have custom dynamic filters apply correctly to both Data Visualizations and record list component while also including some predefined filters on the record list component (e.g. active and assigned to my group). The example is shown in HR Workspace but it should apply the same way to other Workspaces.

1) Create custom filters you'd like to add to your page (in this example I’ll create two for HR Case table)

PDawg_0-1779099363830.png

 

PDawg_1-1779099363830.png

 

 

2) Add some data visualizations and record list component:

PDawg_2-1779099363833.png

 

 

3) Create following client state parameters:

- Name: parFilters
- Type: JSON
- Initial value: simple array

 

- Name: encodedQueries
- Type: JSON
- Initial value: object

- Name: standardFilter  (this will be our predefined filter which should always apply on the record list component, e.g. active and assigned to my groups so it doesn’t display all records by default)

- Type: simple array
- Initial value: encoded query of your choosing (e.g.: active=true^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744^

(ensure to include AND ‘^’ sign at the end)

 

PDawg_3-1779099363836.png

 

 

4) Create a client script which will dynamically update records when custom filters are used

 https://www.servicenow.com/docs/r/washingtondc/now-intelligence/configure-event-handler-filter-lists...

PDawg_4-1779099363838.png

 

Add Client script includes: mergePARFilters

PDawg_5-1779099363839.png

 

Map the client script to custom filters:

PDawg_6-1779099363840.png

 



PDawg_7-1779099363841.png

 

 

5) This will work for Data Visualizations but not for record list yet, to make it work on record list we need to bind the filter as below:

IF(@state.encodedQueries, CONCAT(@state.standardFilter, @STate.encodedQueries.sn_hr_core_case), @STate.standardFilter)

PDawg_8-1779099363842.png

 

This way we’ll apply the standardFilter we’ve created if no dynamic filter is applied 😊

 

Now, we can apply dynamic filters and they should apply on all reports:

PDawg_9-1779099363845.png

 

 

 

ServiceNow article which helped me completing this:
https://www.servicenow.com/docs/r/washingtondc/now-intelligence/configure-event-handler-filter-lists...

And previous community post using a bit different method which worked fine but only for data visualizations:
https://www.servicenow.com/community/developer-blog/set-up-interactive-filter-on-ui-builder-for-data...

 

0 REPLIES 0