Please help with Business Rule Script conditions.

Annie10
Tera Contributor

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

Annie10_0-1715995405484.png

(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);

 

26 REPLIES 26

Sandeep Rajput
Tera Patron
Tera Patron

@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

Hello @Sandeep Rajput ,

Here are the roles the Eform support team has:

Annie10_0-1716006945975.png

 

Community Alums
Not applicable

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

 

gs.getUser().isMemberOf(current.assignment_group)
 
I have tested this in my PDI & it's working.
 
I started answering community questions recently. Please mark it as helpful or correct. It would be a great boost.

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);