Dynamic Filtering Based on User Role When Clicking a Module
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12m ago
Hi, all
I'm developing on ServiceNow and would like to ask for advice on how to dynamically change the filter of a list displayed when a user clicks a module, based on the custom roles the logged-in user possesses.
What I want to achieve:
I aim to apply different filters to the list view opened from a module, depending on the user's role. My goal is to consolidate modules for multiple custom tables into a single module while personalizing the displayed content based on user roles.
Specific Example:
For instance, consider a module for a custom table named "Table A". I want to achieve the following behavior:
- If a user with Role A clicks the module:
- Displayed content: List of "Table A"
- Applied filter: sys_updated_by = logged-in user
- If a user with Role B clicks the module:
- Displayed content: List of "Table A"
- Applied filter: sys_created_by = logged-in user
(The actual filter conditions may be more complex than these examples.)
My Current Attempts and Challenges:
Initially, I tried setting the module's link type to "URL (from Arguments)" and using a javascript: scheme like this:
table_name.do?javascript:new test().getQuery();
My intention was to determine the logged-in user's role within the getQuery() Script Include, generate a query string based on that role, and return it. However, this method did not apply the filters as expected.
My Questions:
- Is there a better way to dynamically apply filters based on a user's role when clicking a module?
- Which ServiceNow features (e.g., Script Includes, Business Rules, UI Scripts) would be most suitable for this implementation?
- Specifically, if there are any best practices for achieving dynamic filtering based on roles while consolidating modules for numerous custom tables, I would greatly appreciate your guidance.
Your assistance would be greatly appreciated. Thank you in advance!
