- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 12:35 AM
We have a module My Risks visible to role sn_risk.user and below is the filter condition.
We receive requirement that when they click the All in the filter, no record should be displayed.
So I created a business rule before-query to preview this
(function executeRule(current, previous /*null when async*/) {
// Only apply restriction if the user is NOT a risk manager and is using the "All" filter
if (gs.getUser() && !gs.hasRole('sn_risk.global_manager')) {
var queryString = gs.action.getGlideURI().toString();
// Apply restriction ONLY when the user is NOT using "My Risks" filter
if (queryString.indexOf('sysparm_query=') !== -1 && queryString.indexOf('owned_byDYNAMIC') === -1 && queryString.indexOf('ownerDYNAMIC') === -1) {
var gr = current.addQuery('owned_by', gs.getUserID());
gr.addOrCondition('owner', gs.getUserID()); // Ensures correct OR condition
}
}
})(current, previous);
However, I created another module ATK Site Risk visible to role sn_risk.atk_site_risk and condition is below:
When I impersonated a user with role sn_risk.atk_site_risk, open the ATK Site Risks, there are no records.
I tried to deactivate the business rule and there are records. But I need the business rule to prevent the All filter
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 12:59 AM
why not use sysparm_fixed_query as URL arguments from module, with this they cannot click All
Restrict filters and breadcrumbs with fixed queries
you will see lot of OOB modules for this
Copy your query and give it after this
&sysparm_fixed_query=YOUR QUERY
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 12:41 AM
determining the URL in query business rule is somewhat trickier
why are you checking the URL?
simply try this
(function executeRule(current, previous /*null when async*/ ) {
// Only apply restriction if the user is NOT a risk manager and is using the "All" filter
if (!gs.hasRole('sn_risk.global_manager')) {
// Apply restriction ONLY when the user is NOT using "My Risks" filter
var gr = current.addQuery('owned_by', gs.getUserID());
gr.addOrCondition('owner', gs.getUserID()); // Ensures correct OR condition
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 12:59 AM
why not use sysparm_fixed_query as URL arguments from module, with this they cannot click All
Restrict filters and breadcrumbs with fixed queries
you will see lot of OOB modules for this
Copy your query and give it after this
&sysparm_fixed_query=YOUR QUERY
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader