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.

Restrict access of tickets per group

Pat Surtan
Tera Expert

Hello Everyone,

 

I have a custom table where 3 different teams can access. Team 1 can see all tickets. Team 2 can only see tickets assigned to their category and team 3  can only see tickets assigned to their category as well. How can I achieve this? Please provide detailed steps and thank you in advance.

11 REPLIES 11

Just to update my requirement:

 

1. Team 1 can see everything except for 1 group's ticket.

2. Team 2 can see only their group's tickets.

3. Team 3 can only see their group's tickets.

 

How many BR will I need to satisfy all 3 requirements?

Here is my before business rule for #1, team 1 can see all tickets except for 1 group's tickets:

 

When: Before

Order: 100

Query = True

(function executeRule(current, previous /*null when async*/ ) {
    if (!gs.getUser().isMemberOf('my group name')) {
        current.addQuery('assignment_group', 'my group sys id');

                }
})(current, previous);

 

This restrict access from 159 tickets down to 7, which is not correct. I should be able to see more than this. What am I doing wrong?

Hey @Pat Surtan ,

can be kept in the same BR:
Modify your code as:

Scenario 1:

if (gs.getUser().isMemberOf('my group name 1')) {
        current.addQuery('assignment_group', '!=','my group 1 sys id');

 }

Scenario 2:

if (gs.getUser().isMemberOf('my group name 2')) {
        current.addQuery('assignment_group','my group 2 sys id');

 }

 

Scenario 3:

if (gs.getUser().isMemberOf('my group name 3')) {
        current.addQuery('assignment_group','my group 3 sys id');

 }

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Hello Aman,

 

What happens if a user is in group 2 and 3? Will they be able to see the tickets for both in a combined view? Or will one take precedence over the other? I have a user that is in both groups 2 and 3 so this person needs to see tickets for both groups. However, groups 2 and 3 have different members.

You will need to build a different logic for it then:

if (gs.getUser().isMemberOf('my group name 1')) {
        current.addQuery('assignment_group', '!=','my group 1 sys id');

 }

else if (gs.getUser().isMemberOf('my group name 2') && gs.getUser().isMemberOf('my group name 3') ) {
        current.addEncodedQuery('assignment_groupINmy group 2 sys id,my group 3 sys id');

 }

else if (gs.getUser().isMemberOf('my group name 2')) {
        current.addQuery('assignment_group','my group 2 sys id');

 }

else if (gs.getUser().isMemberOf('my group name 3')) {
        current.addQuery('assignment_group','my group 3 sys id');

 }

Best Regards
Aman Kumar

Hi Aman,

Looks like the logic is built around what users are in the groups. So what happens if we need expand the build on this logic? Say, we add group 4, 5, and 6. Then a user from group 2 has access to groups 4 and 5. A user from group 3 has access to groups 5 and 6? The logic will need to keep being updated based on the users switching groups?

What does this part ('assignment_groupINmy group 2 sys id,my group 3 sys id'); mean? How should it look? I don't think I have the correct syntax or query for this. Should it be like this?current.addEncodedQuery('sys id for group 2,sys id for group3'); ?