- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 03:52 AM
Hello Team,
I got a requirement where I need to filter or show 'HR' catalog Item (RITM) records to specific user i.e.,
If is part of group xyx or
If user is part of group abc or
If user is Requested For.
I tried writing query business rule on RITM table with the below script but somehow it's not working could any one please help me with your inputs to achieve this scenario.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 04:46 AM - edited ‎05-05-2025 04:48 AM
Hi @Ram141
I have create query BR which handles all of your 3 scenarios:
- If user is not part of XYZ and ABC group-> HR system requests will be hidden.
- If user is not part of XYZ and ABC group but he is requested by or opened by person-> only those records will be visible to user.
- If user is neither part of XYZ, ABC group nor he is requested for -> All HR system requests will be hidden.
I have created new Query BR on PDI and tested and it works prefectly.
PFB script for your reference:
(function executeRule(current, previous /*null when async*/ ) {
var curUserID = gs.getUserID();
var user = gs.getUser();
var xyz = '1ab75ae587e19a90b865206acebb3591';
var abc = '4f37a9983b465ad0cb51624a85e45afe';
if (!user.isMemberOf(abc) && !user.isMemberOf(xyz)) {
var currentQuery=current.addQuery('cat_item.name','!=','HR System Requests');
var currentQuery2 = currentQuery.addOrCondition('requested_for', curUserID);
currentQuery2.addOrCondition("opened_by",curUserID); //Hide HR System Requests RITM's for all users except for requester for and opened by user
}
})(current, previous);
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 05:12 AM
try this
Also ensure table.None READ ACL on sc_req_item allows the access
(function executeRule(current, previous) {
var userId = gs.getUserID();
var groupXYZ = '1ab75ae587e19a90b865206acebb3591';
var groupABC = '4f37a9983b465ad0cb51624a85e45afe';
// Filter HR catalog items
current.addQuery('cat_item.name', 'HR System Requests');
// Restrict visibility if user isn't in groups
if (!user.isMemberOf(groupXYZ) && !user.isMemberOf(groupABC)) {
current.addQuery('request.requested_for', userId); // Only show user's own requests
}
})(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
‎05-05-2025 05:46 AM - edited ‎05-05-2025 05:46 AM
@Ankur Bawiskar The scenario is even if user is not part of group abc and xyz but part of 'Requested By' field then also user should be able to access the Ritm records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 05:58 AM
Hi @Ram141
That's what my script does, please have a look.
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 06:14 AM
Thanks @Abhijit4 In filter condition do we need to provide Item is 'Hr system Requests' as this query BR may apply to all items.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2025 06:22 AM - edited ‎05-05-2025 06:26 AM
This is what you need to do to achieve your scenario:
var curUserID = gs.getUserID();
var user = gs.getUser();
var xyz = '1ab75ae587e19a90b865206acebb3591';
var abc = '4f37a9983b465ad0cb51624a85e45afe';
if (!user.isMemberOf(abc) && !user.isMemberOf(xyz)) {
var currentQuery=current.addQuery('cat_item.name','!=','HR System Requests'); //Hide HR System Requsts for all users who are not part of ABC or XYZ group.
var currentQuery2 = currentQuery.addOrCondition('requested_for', curUserID);
currentQuery2.addOrCondition("opened_by",curUserID); //Hide HR System Requests RITM's for all users except for requester for and opened by user
}
I have added explanation beside filter query. Hope that clarifies your concern.
Let me know if you still have any questions.
Regards,
Abhijit
ServiceNow MVP