User case access

Community Alums
Not applicable

I was having a group which is having access to 2 users let the group name hr and there was another group which is payroll. There was user who belongs only to the payroll group and he was able to see the cases which was assigned to the hr group. There was no coe security present on hr group but still the users with hr basic role able to see the hr assignment group cases. Can anyone help me how to fix this issue

8 REPLIES 8

Community Alums
Not applicable

@Ankur Bawiskar 

Yes i am sure that user belongs to only these group this problem arise with other groups as well. All the group users able to see the hr group cases.

and i have verified the configuration of that coe policy and there is no coe policy created on hr group as well

Runjay Patel
Giga Sage

Hi @Community Alums ,

 

Try below code in before query BR.

(function executeRule(current, previous /*null when async*/) {
    // Check if the user is part of the payroll group
    var payrollGroupID = 'sys_id_of_payroll_group'; // Replace with the sys_id of the payroll group
    var hrGroupID = 'sys_id_of_hr_group'; // Replace with the sys_id of the HR group

    // Create a GlideRecord to check group membership
    var userGroups = new GlideRecord('sys_user_grmember');
    userGroups.addQuery('user', gs.getUserID());
    userGroups.addQuery('group', payrollGroupID);
    userGroups.query();

    if (userGroups.hasNext()) {
        // If the user is in the payroll group, exclude HR cases
        current.addQuery('assignment_group', '!=', hrGroupID);
    }
})(current, previous);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Community Alums
Not applicable

Hi @Runjay Patel 

Can you please give me a clarity if user is not a part of the group they should not the see the case right? If yes then whats the need to creating a business rule and updating the scripting. I was confused can you please provided me a clarity on this

Hi @Community Alums ,

 

I have given you code to not show the case when user does not belongs to group.