Need a Reference Qualifier on a Catalog Item Variable to filter by the requester's managers groups?

JR42
Giga Guru

Hi.  I need to present a variable in a request form for a Catalog Item that allows the requester to select one of their manager's assignment groups from sys_user_group. 

How can I create a reference qualifier on the variable so that only the requester's manager's groups are available as options? 

 

Thanks!

 

1 ACCEPTED SOLUTION

Ok so what you can try to do in the original script is add the following line to get your support groups. 

gr.addQuery('group.type', 'CONTAINS','eb6c00b0db3700507e99e855ca9619b5'); //this needs to be the sys_id of the group type you want

 

View solution in original post

17 REPLIES 17

Hi, Bryan.  Thank you.  This script is working and showing the groups that the manger manages.  After seeing the results, I've determined that I will need to use the groups that the user's manager is a member of, instead of groups that they manage.  For example, one user's manager is a member of 5 visible support groups, but only a manager for one.  With the current script, only one group is returned.

Ok so what you can try to do in the original script is add the following line to get your support groups. 

gr.addQuery('group.type', 'CONTAINS','eb6c00b0db3700507e99e855ca9619b5'); //this needs to be the sys_id of the group type you want

 

JR42
Giga Guru

@Brian Lancaster @Alka_Chaudhary Thank you both for the help.  It's working great.

Here's the details of the working build:

 

Reference qualifiers:

Manager's groups

     javascript: new getRequestedForDetails().getReqManagerGroup(gs.getUserID());

User's groups

     javascript: new getRequestedForDetails().getReqUserGroups(gs.getUserID());

 

Script Include: getRequestedForDetails

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

    getReqManagerGroup: function(userid) {
        var user = new GlideRecord('sys_user');
        user.addQuery('sys_id', userid);
        user.query();
        if (user.next()) {
            var arrGroup = [];
            var gr = new GlideRecord('sys_user_grmember');
            gr.addQuery('user', user.manager);
            gr.addQuery('group.type', 'CONTAINS', 'f429f94c0a0a3c9801ecd71fa6749366'); //sys_id of the group type: support
            gr.query();
            while (gr.next()) {
                arrGroup.push(gr.group.toString());
            }
        }

        return 'sys_idIN' + arrGroup;
    },

    getReqUserGroups: function(userid) {
        var user = new GlideRecord('sys_user');
        user.addQuery('sys_id', userid);
        user.query();
        if (user.next()) {
            var arrGroup = [];
            var gr = new GlideRecord('sys_user_grmember');
            gr.addQuery('user', user.sys_id); // Changed from user.manager to user.sys_id
            gr.addQuery('group.type', 'CONTAINS', 'f429f94c0a0a3c9801ecd71fa6749366'); //sys_id of the group type: support
            gr.query();
            while (gr.next()) {
                arrGroup.push(gr.group.toString());
            }
            return 'sys_idIN' + arrGroup;
        } else {
            return []; // Return an empty array if user is not found
        }
    },

    type: 'getRequestedForDetails'
});