Display users NOT belonging to specific group in a catalog variable

Somujit1
Tera Contributor

Hello,

 

For a catalog item, I have a requirement to display members not belonging to a specific group on a catalog variable referencing to sys_user table.

I have written the below global not client callable script include as -

 

var getNonItilUsers = Class.create();
getNonItilUsers.prototype = {
        initialize: function() {},
            getUser: function() {
                var userName = [];
                var users = new GlideRecord('sys_user');
                users.addActiveQuery();
                users.query();
                while (users.next()) {
                    var userGroup = new GlideRecord('sys_user_grmember');
                    userGroup.addQuery('user', users.sys_id);
                    userGroup.addQuery('group','a671c95edb875910cb183632f39619bf');
                    userGroup.query();
                    if (!userGroup.hasNext()) {
                        userName.push(users.getDisplayValue());
                    }
                    return userName
                }
            },

            type: 'getNonItilUsers'
        };
 
On the variable advanced reference qualifier, i have defined as -
javascript:new getNonItilUsers().getUser();
 
However, the variable displays users belonging to the group which i sys_id'ed when testing the catalog item.
 
Note: To test the script include, I ran it in a background script using gs.print(users.getDisplayValue()), and it works fine.
 
Can you please let me know what i am doing wrong to achieve this scenario?
 
Thanks,
Somujit
5 REPLIES 5

@Daniel Borkowi1 ,

I tried the script as shared with you. However, the reference variable dropdown is not restricting the users belonging this group form being displayed, and is displaying all the users.

Below is the script include and variable advance ref qualifier -

Somujit1_2-1727054754140.png

 

Somujit1_1-1727054562387.png

Thanks