Query Business rule based on assignment group

pooja53
Kilo Explorer

Hi Team,

I am writing the query Business rule. Where if Logged in user is member of that group, then only incidents belongs to that assignment group should be visible.

Before query business rule on Incident.

it works when I send Sys_id of that group example:

if(gs.getUser().isMemberOf('f795ab34db230010bdfd0181ca96196b'))
{
current.addQuery('assignment_group','f795ab34db230010bdfd0181ca96196b');
}

Its Not working below one.

if(gs.getUser().isMemberOf(current.assignment_group))
{
current.addQuery('assignment_group',current.assignment_group);
}

 

7 REPLIES 7

Adrian Script will work after making one modification:

if (gs.getUser().isMemberOf(gs.getProperty('property_name'))) {
current.addQuery('assignment_group', gs.getProperty('property_name'));

}

 

If it was helpful, Please mark it helpful.

Harshal Aditya
Mega Sage
Mega Sage

Hi Pooja,

You have to pass Sys_ID if you are using before query BR. As it runs when any user queries any table. So cunnent.assignment group will not work.

Regards

Harshal

 

sayed3
Tera Contributor

Before Query business rule:

(function executeRule(current, previous /*null when async*/) {
 
    var userGroupsRaw = gs.getUser().getMyGroups();
 
    var userGroups = Array.isArray(userGroupsRaw) ? userGroupsRaw : Array.from(userGroupsRaw || []);
 
    gs.info("User Groups: " + JSON.stringify(userGroups));
 
    if (userGroups.length > 0) {
 
        var groupFilter = userGroups.map(function(groupId) {
            return "assignment_group=" + groupId;
        }).join("^OR");
 
        gs.info("Constructed group filter: " + groupFilter);
 
        var query = "active=true^" + groupFilter;
        gs.info("Final encoded query: " + query);
        current.addEncodedQuery(query);
 
    } else {
 
        gs.info("User has no groups; applying ISEMPTY filter");
        current.addEncodedQuery("active=true^assignment_groupISEMPTY");
    }
 
})(current, previous);