Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Show Incidents created by or assigned to particular group members.

AnilM99
Tera Expert

Hi Team,

 

I have 3 groups

1. ServiceDesk 

2. Hardware

3. Software

 

ServiceDesk group members can see their incidents and other 2 group incidents

Other 2 group members can only see their group incidents, but they should not see ServiceDesk groups or the other groups.

 

Help me on the same

 

Thanks

Anil!

 

2 REPLIES 2

Saloni Suthar
Giga Sage
Giga Sage

Hi @AnilM99 ,

It is achievable only if Hardware and Software group members are not part of the Service Desk group. Please see the solution below: 
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0790987


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

Yashsvi
Kilo Sage

Hi @AnilM99,

try below BR:

(function executeBeforeQuery(current, previous /*, displayValue, tableName*/) {
    var userGroups = gs.getUser().getRoles(); // Get roles of the current user

    if (userGroups.includes('ServiceDesk Group')) {
        // Allow ServiceDesk Group to see all incidents
        // No filtering needed
    } else if (userGroups.includes('Hardware Group')) {
        // Filter incidents to show only those of Hardware Group
        current.addQuery('assignment_group', 'hardware_group_sys_id');
    } else if (userGroups.includes('Software Group')) {
        // Filter incidents to show only those of Software Group
        current.addQuery('assignment_group', 'software_group_sys_id');
    } else {
        // Default behavior if no specific group condition is met
        current.addQuery('sys_id', '!=', ''); // Some condition to always return an empty result
    }
})(current, previous /*, displayValue, tableName*/);

and also check below link:

https://www.servicenow.com/community/itsm-forum/incidents-created-by-particular-group-members/td-p/7...

https://www.servicenow.com/community/developer-forum/how-can-list-all-incidents-raised-by-my-group-m...

Thank you, please make helpful if you accept the solution.