Before Query Business Rule to restrict access
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 01:53 PM
Can someone please help me with a query business rule to achieve this requirement?
Vendors should only be able to see records actively assigned to them via their group.
All help is greatly appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 04:50 PM
@Zubair Alam2 if you already started working on this BR please post the script. I can help to review and provide any suggestions.
Please mark my answer correct and helpful if this works for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 06:51 PM
@Zubair Alam2 You can add script in your BR similar to below to achieve same :
if (gs.hasRole('vendor')) { // Check if the user is a vendor
var groupIDs = [];
var userGr = new GlideRecord('sys_user_grmember');
userGr.addQuery('user', gs.getUserID());
userGr.query();
while (userGr.next()) {
groupIDs.push(userGr.group.toString());
}
// Restrict query to only records assigned to the user's groups
if (groupIDs.length > 0) {
current.addQuery('assignment_group', 'IN', groupIDs.join(','));
current.addQuery('active', true); // Only active records
} else {
// If the user is not in any group, prevent access
current.addQuery('sys_id', 'DOES NOT EXIST');
}
}
Hope this will help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 08:26 PM
unless you share what you started with and what debugging have you done so far, we won't be able to help much
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 06:27 AM
Hi @Ankur Bawiskar
This is what I have put together so far but it is failing a couple of tests. I am not sure what is missing. Please help. Thanks.
It gets the groups for the logged in user.
Then checks if any of those groups are marked as vendor. (u_vendor_group = Tur on sys_user_group).
If the user is in any vendor groups, it is supposed to restrict the records the user can see.
The requirement is : All vendor group members only be able to see tickets assigned to the vendor groups they belong to only.