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

Community Alums
Not applicable

Hi,

 

Consider i am member of a group called "Service".

There are 10 RITM's in total.

Out of 10

- 3 are assigned to "service" group 

- 1 is opened by me 

- 1 is requested for me 

 

If I logged in to the system I should be able to see only 5 RITM's out of 10.

 

Is this your requirement?

@Community Alums 

Thank you for helping.  That is perfectly correct.

Community Alums
Not applicable

@Annie10  In this case there is no need for any BR. You can follow the steps I mentioned in earlier reply.

 

I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.

@Community Alums ,

I have never modify the ACL before, Where do I enter this code the you provided:

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

 

Annie10_0-1716008642643.png

 

 

 

Maddysunil
Kilo Sage

@Annie10 

  1. Redundant Queries: It appears that the line current.addQuery('assignment_group', '927934e41b6bf0104425cb35624bcbe9'); is redundant as the same query condition is already being added in var qc.

  2. Proper Query Construction: Ensure that the queries are built correctly and logically.

 

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

 

  

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks