Reference field should populate members of a group. I have a reference field  "Name" which is refer

Archana23
Tera Contributor

Reference field should populate members of a group.

I have a reference field  "Name" which is referenced to sys_user table. Right now I have all users being populated, but I want users which are a part of 10 group  members only to be included in this. 

I know it requires a script include and javacript on the reference qualifier. Could someone help me with the script include and how to call is on the advanced  reference qualifier. 

 

6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@Archana23 Here is the script include code.

 

var UserGroupFilter = Class.create();
UserGroupFilter.prototype = {
    initialize: function() {},

    getFilteredUsers: function() {
        var allowedGroups = [
            'GROUP_SYS_ID_1',
            'GROUP_SYS_ID_2',
            'GROUP_SYS_ID_3',
            'GROUP_SYS_ID_4',
            'GROUP_SYS_ID_5',
            'GROUP_SYS_ID_6',
            'GROUP_SYS_ID_7',
            'GROUP_SYS_ID_8',
            'GROUP_SYS_ID_9',
            'GROUP_SYS_ID_10'
        ];
//Replace the GROUP_SYS_ID_1....../GROUP_SYS_ID_ with the actual sys_ids of the groups
        var users = [];
        var gr = new GlideRecord('sys_user_grmember');
        gr.addEncodedQuery('groupIN' + allowedGroups.join(','));
        gr.query();
        while (gr.next()) {
            users.push(gr.user.toString());
        }

        return 'sys_idIN'+users.join(',');
    },

    type: 'UserGroupFilter'
};

Reference qualifier:

javascript: new UserGroupFilter().getFilteredUsers();

Hi @Sandeep Rajput ,

Please help me with system property to store groups

Put gs.getProperty('Property name');

Please help me in calling that in script include and complete script