Filter users based on location
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2024 01:04 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2024 05:51 AM - edited 03-28-2024 06:41 AM
@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:
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:
I hope this answers your question! 🙂
If it does, kindly mark it as answered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 06:25 AM
@Revathi12 Hello,
Does my proposal solve your request?