The CreatorCon Call for Content is officially open! Get started here.

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

VarunS
Kilo Sage

@Annie10  try with the below script.

 

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

    if (!gs.hasRole("itil") && gs.getSession().isInteractive()) {
        var u = gs.getUserID();
        var userGroups = gs.getUser().getMyGroups(); // Get groups the user belongs to

        // Query for records where the user is the requested_for, opened_by, in the watch_list, or in their assignment group
        var qc = current.addQuery("requested_for", u)
                        .addOrCondition("opened_by", u)
                        .addOrCondition("watch_list", "CONTAINS", u);
        
        // Add conditions for user's assignment groups
        var groupCondition = qc.addOrCondition("assignment_group", userGroups[0]);
        for (var i = 1; i < userGroups.length; i++) {
            groupCondition.addOrCondition("assignment_group", userGroups[i]);
        }

        gs.info("Query restricted to user: " + u);
    }

})(current, previous);

Annie10
Tera Contributor

Hi @VarunS 

I'm trying to understand the following error after executed the BS. What is it means and how to fix it?

==== Error and stack:
org.mozilla.javascript.EvaluatorException: Java class "com.glide.collections.StringList" has no public instance field or method named "0". (sys_script.1c446a8e835a4a1008469796feaad356.script; line 13)