- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 01:07 AM
Hi All,
Current logged in user should see only those incidents which are assigned to those groups which he/she is member of. Suppose a user is member of 3 groups. Please explain with the script.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 01:18 AM
Hi @mohit4sharm ,
Certainly! To restrict incidents to only the groups a user is a member of in ServiceNow, you can use **Access Control Lists (ACLs)**. Here's an example script that achieves this:
```javascript
// This script should be placed in the read ACL for the incident table
// It restricts visibility to incidents assigned to the user's groups
answer = current.assignment_group.getMembers().contains(gs.getUserID());
```
In this script:
- `current` refers to the current incident record.
- `assignment_group` represents the assignment group field on the incident.
- `getMembers()` retrieves the users who are members of the assignment group.
- `contains(gs.getUserID())` checks if the current user is among those group members.
By using this script, incidents will only be visible to users who belong to the same groups as the assignment group.
Please mark my answer "Accept as solution" and "Helpful" if this works for you
Thanks & Regards
Adarsh Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 01:13 AM
you can try before query business rule
(function executeRule(current, previous /*null when async*/) {
// Get the current user's ID
var userID = gs.getUserID();
// Create an array to hold the user's group IDs
var userGroups = [];
// Query the sys_user_grmember table to get the groups the user belongs to
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('user', userID);
grMember.query();
// Add each group ID to the userGroups array
while (grMember.next()) {
userGroups.push(grMember.group.toString());
}
// If the user is not a member of any groups, return no results
if (userGroups.length === 0) {
userGroups.push("none");
}
// Add a query to filter incidents by the user's groups
current.addQuery('assignment_group', 'IN', userGroups.join(','));
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 01:14 AM
Hi,
Is this across all UIs or just in a particular one? Is this wanted at the security level (so they can't access something they're not related to) or presentation (filtered report / menu) ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 01:18 AM
Hi @mohit4sharm ,
Certainly! To restrict incidents to only the groups a user is a member of in ServiceNow, you can use **Access Control Lists (ACLs)**. Here's an example script that achieves this:
```javascript
// This script should be placed in the read ACL for the incident table
// It restricts visibility to incidents assigned to the user's groups
answer = current.assignment_group.getMembers().contains(gs.getUserID());
```
In this script:
- `current` refers to the current incident record.
- `assignment_group` represents the assignment group field on the incident.
- `getMembers()` retrieves the users who are members of the assignment group.
- `contains(gs.getUserID())` checks if the current user is among those group members.
By using this script, incidents will only be visible to users who belong to the same groups as the assignment group.
Please mark my answer "Accept as solution" and "Helpful" if this works for you
Thanks & Regards
Adarsh Verma