Filter users based on location

Revathi12
Tera Contributor

Hi Team,

 

Can anyone help me with the script on how to filter users based on the location selected. I have 2 fields one is location and other is user, if I select location I need to populate user based on the location selected.

 

Thanks

6 REPLIES 6

@Revathi12 
If you need it for a reference field, you should override the Reference qualifier in sys_dictionary table and include the script include. 
For example:

kkrushkov_0-1711543415674.png


Script Include:

 

var UserFilterLocation = Class.create();
UserFilterLocation.prototype = {

    getUsersByLocation: function(location) {
        //You check if the location is empty. If it is you don't include it in the reference qualifier and return.
        if (!location) return '';
        var userList = [];

        var userGr = new GlideRecord('sys_user');
        userGr.addQuery('location', location);
        userGr.query();
        while (userGr.next()) {
            userList.push(userGr.getUniqueValue());
        }

        return "sys_idIN" + userList.join(',');
    },

    type: 'UserFilterLocation'
};

 

 

You can also accomplish this without using Script Include by doing the following:

kkrushkov_1-1711633280200.png

 

I hope this answers your question! 🙂
If it does, kindly mark it as answered.

@Revathi12 Hello, 

Does my proposal solve your request?