How to filter groups to which the user is assigned to.

Pablo H
Tera Contributor

Hello all,

I have created a new reference field on the sys_user table and I want to create a reference qualifier that would only show active groups to which the given user is assigned to. Any idea how to achieve this? Thank you

 

For example, as a system admin I want to assign a primary group to Abel Tuter, but it needs to be active group to which he is assigned to.

1 ACCEPTED SOLUTION

Actually, if you're looking for a reference to the Group, which I assume you are, you may want to created a Script Include that builds a query string for you of all the sys_ids of the group the user is a member of.

var UserRefQual = Class.create();
UserRefQual.prototype = {
    initialize: function() {},
    getGroups: function(user) {
        var groups = [];

        var grUserGrp = new GlideRecord('sys_user_grmember');
        grUserGrp.addQuery('user', user.sys_id);
        grUserGrp.query();

        while (grUserGrp.next())
        {
            groups.push(grUserGrp.group);
        }
		gs.info("sys_idIN" + groups);
        return "sys_idIN" + groups;
    },
    type: 'UserRefQual'
};

And in your reference qualifier, you can use this:

javascript: new global.UserRefQual().getGroups(current);

Make sure you change your reference field to Group. You won't have to worry about display values that way.

View solution in original post

11 REPLIES 11

This was also helpful to me, i just changed the refence qualifier to get group of the field

javascript: new global.UserRefQual().getGroups(current.variable.requested_for);

This worked, however I had to add to the following to the line below to get all groups to display:

groups.push(grUserGrp.group);

 Added:

groups.push(grUserGrp.group+'');

 

Thank you very much for the help.