business rule query active=true

Baggies
Kilo Guru

Hello,

I have a business rule with an advanced script. The BR is called by a reference type variable on a catalog item to filter the users only belonging to a specific group.

BUT, I want to filter only on users that are ALSO active. I have tried adding the addEncodedQuery method, but nothing is working for me. I am able to filter on the group members just fine with the variable reference qualifier:

javascript:"sys_idIN"+getGroupedUsers("IN","Hardware, Forensics").join(",")

My BR script is:

function getGroupedUsers(queryCondition, groupList) {
    var groupListIds;
    if (queryCondition && groupList) { groupListIds = getGroupListIds(groupList); }
        
        var users = {};
            var gr = new GlideRecord('sys_user_grmember');
                
            if (groupListIds) { gr.addQuery('group', queryCondition, groupListIds); }
                
                gr.query();
                while (gr.next()) { users[gr.user.toString()] = true; }
                                        
                    var ids = [];
                    for (var id in users) { ids.push(id); }
                        return ids;
                    }
                    
                    // get sys_ids for the named groups
                    function getGroupListIds(groupList) {
                        var ids = [];
                        var gr = new GlideRecord('sys_user_group');
                        
                        gr.addQuery('name','IN',groupList);
                        gr.query();
                        
                        while (gr.next()) { ids.push(gr.sys_id.toString()); }
                            return ids;
                        }


Any assistance in additionally filtering on active users is greatly appreciated. Cheers, Mark S.

1 ACCEPTED SOLUTION

Did this answer your question?  Please mark my response correct if it did.  Thanks!

View solution in original post

3 REPLIES 3

Mark Stanger
Giga Sage

gr.addQuery('user.active', true); right after your 'gr.addQuery('group')' line should do what you want.

Did this answer your question?  Please mark my response correct if it did.  Thanks!

Hello Mark, many thanks, it was the 'user' bit I didnt get right in my attempts. Long time no hear, it was one of the first Knowledge conf in San Diego when we met - BC Lottery days. Cheers, Mark S.