Please help with Business Rule Script conditions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 06:24 PM
Hello,
Could someone please help review the code? It is not working. The purpose of the business rule is to allow users to see records that are assigned to their team, but not records assigned to other teams. Thank you.
When to Run: Before, Query
(function executeRule(current, previous /*null when async*/) {
if (!gs.hasRole("itil") && gs.getSession().isInteractive()) {
var u = gs.getUserID();
var qc = current.addQuery("requested_for", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u).addOrCondition('assignment_group', '927934e41b6bf0104425cb35624bcbe9');
gs.info("query restricted to user: " + u);
current.addQuery('assignment_group', '927934e41b6bf0104425cb35624bcbe9');
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 08:29 PM
@Annie10 What roles does Group with sys_id 927934e41b6bf0104425cb35624bcbe9 have if it has itil role then then the condition would fail at line number 1 of the business rule itself.
The rows
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 09:36 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 08:45 PM - edited 05-17-2024 08:45 PM
Hi @Annie10 ,
If someone wants to view the requested items which are
- opened by them or
- requested for them or
- assigned to one of the groups they were part of
you don't need a query BR.
There is an OOTB ACL which does the job.
https://instanceName.service-now.com/sys_security_acl.do?sys_id=d9694407c3923000c111113e5bba8ffd&sysparm_view=&sysparm_domain=null&sysparm_domain_scope=null&sysparm_record_row=5&sysparm_record_rows=14&sysparm_record_list=name%3dsc_req_item%5eORnameSTARTSWITHsc_req_item.%5eoperation%3dread%5eORDERBYDESCsys_updated_on
The above ACL will check for opened by & requested for by default. So, to check assignment group add the below code to the script in condition field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 09:40 PM
Sorry @Community Alums I accidentally clicked 'accept.'
How to I modify the code to make it works:
(function executeRule(current, previous /*null when async*/) { if (!gs.hasRole("itil") && gs.getSession().isInteractive()) { var u = gs.getUserID(); var qc = current.addQuery("requested_for", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u).addOrCondition('assignment_group', '927934e41b6bf0104425cb35624bcbe9'); gs.info("query restricted to user: " + u); current.addQuery('assignment_group', '927934e41b6bf0104425cb35624bcbe9'); } })(current, previous);