Reference qualifier to allow user to select users from his/her group only

Naveen Bandaru
Tera Contributor

I have created a script include to return the group of current logged in user.

Its returning fine when i checked in background script.

and added the above script include in dynamic filter option and configured it in dictionary for Caller reference field but still it returns all the users instead of group members only.

 

 

Script Include:

var getGroupsOfCurrentLoggedInUser = Class.create();
getGroupsOfCurrentLoggedInUser.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getGroup:function(){

        var gr=new GlideRecord('sys_user');
        gr.addQuery('sys_id',gs.getUser().getID());
        gr.query();
        if(gr.next()){
            var groups=new GlideRecord('sys_user_grmember');
            groups.addQuery('user',gr.sys_id);
            groups.query();
            if(groups.next()){
                return groups.group.name.toString();
            }       }

    },
    type: 'getGroupsOfCurrentLoggedInUser'
});
 
 
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

You can try gs.getUserID() instead of the other method in your addQuery.  Add a log of this value to confirm which way (or both) works.  Since you will have the current user's sys_id, you don't need two GlideRecords, and you'll want to push the USER SYSIDs to an array, not a group name since it sounds like you want to select user(s), not groups.  So it will look more like this:

 getGroup:function(){
    var user = gs.getUser().getID();
    gs.info('Dynamic RQ getUser method = ' + user);
    user = gs.getUserID();
    gs.info('Dynamic RQ getUserID method = ' + user);
    var usersArr = [];
    var groups=new GlideRecord('sys_user_grmember');
    groups.addQuery('user', user);
    groups.query();
    while (groups.next()) {
        usersArr.push(groups.user.toString());
    }
    return usersArr.join(',');

    },

 

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

You can try gs.getUserID() instead of the other method in your addQuery.  Add a log of this value to confirm which way (or both) works.  Since you will have the current user's sys_id, you don't need two GlideRecords, and you'll want to push the USER SYSIDs to an array, not a group name since it sounds like you want to select user(s), not groups.  So it will look more like this:

 getGroup:function(){
    var user = gs.getUser().getID();
    gs.info('Dynamic RQ getUser method = ' + user);
    user = gs.getUserID();
    gs.info('Dynamic RQ getUserID method = ' + user);
    var usersArr = [];
    var groups=new GlideRecord('sys_user_grmember');
    groups.addQuery('user', user);
    groups.query();
    while (groups.next()) {
        usersArr.push(groups.user.toString());
    }
    return usersArr.join(',');

    },