Restrict visibilty of tickets based on Assignment group

KARAN24
Tera Contributor

Hi Team,

We have 5 towers such as A,B,C,D and E and each tower has different assginment group,and we can differiantate the assignment group on the basis of Type field in Groups table, So we want members who belongs to any one of the towers and its respective assigmnet group,should not be visible to see tickets of other towers or should not be able to redirect tickets to them.

How we can achieve this.

 

Regards,

Karan

8 REPLIES 8

Aman Kumar S
Kilo Patron

You can follow below link to achieve the same.

You are looking for Before Query BR

https://servicenowguru.com/scripting/business-rules-scripting/controlling-record-access-before-query...

Best Regards
Aman Kumar

Community Alums
Not applicable

Hi Karan,

It can be done by two approaches, 1. Using BR and 2. using ACL.

But  I suspect that a 'BR query' would hide the record and ACL would be the most suitable approach for making it read only.

OOB the platform has a number of ACL's that check if the user is a member of the current.assignment_group and you should be able to use these as a reference.

/sys_security_acl_list.do?sysparm_query=scriptLIKEgs.getUser().isMemberOf&sysparm_view=

OR, if you want to go with BR, then try something like this :

var u = gs.getUserID();

if((!u.isMemberOf(current.assignment_group) && current.caller_id != u && current.opened_by != u) && gs.getSession().isInteractive()){

        var q = current.addQuery('assignment_group', getMyGroups()).addOrCondition('caller_id', u).addOrCondition('opened_by', u).addOrCondition("watch_list", "CONTAINS", u);  

}

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

Hi Sandeep,

I tried the below code:

var u = gs.getUserID();

if((!u.isMemberOf(current.assignment_group) && current.caller_id != u && current.opened_by != u) && gs.getSession().isInteractive()){

        var q = current.addQuery('assignment_group', getMyGroups()).addOrCondition('caller_id', u).addOrCondition('opened_by', u).addOrCondition("watch_list", "CONTAINS", u);  

}

 

but its not working,I am doing it for Cases in CSM.

Thanks,

Karan

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Is the ticket table being referred here is incident table?

If yes then you can update the OOB query BR on that incident table and restrict it

Sample Script would look like this

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());

	current.addQuery('assignment_group', "IN", groups.toString());

})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader