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

@Archana23 Create a comma separated list of sys_ids and put it inside the system property. Here is how you can put it inside the script include.

 

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

    getFilteredUsers: function() {
        var allowedGroups = gs.getProperty('allowed.groups');
//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'
};

 

Create a system property with name allowed.groups and put a comma separated list of sys_ids in it.

@Archana23 Please refer to this video https://www.youtube.com/watch?v=CmBvpriwrQQ to know the steps to add a system property.