Setting up custom dynamic filters with predefined filter for record list in UI Builder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
19m ago
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:
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)
2) Add some data visualizations and record list component:
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)
4) Create a client script which will dynamically update records when custom filters are used
Add Client script includes: mergePARFilters
Map the client script to custom filters:
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)
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:
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...
