- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2016 06:06 AM
Hi
I have a variable set that includes a Line Manager field. This Variable is a reference field, looking at the sys_user table. I would like to be able to filter the results returned in the reference field based on the logged in User's current department. Under Type Specifications I've added reference qualifier conditions of:
- Active = True
- Company is (dynamic) My Company
- Department = Department
However, this set of filters is returning all users matching the logged in user's Company, but is ignoring Department.
Would anyone know of a way to do this?
Thanks
Mike
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2016 06:28 AM
Hi Mike,
It is good and easy to use the filtered conditions like above, but it is usually good to go for a script include and function in the reference qualifier - in the condition.
The most important advantage of this kind of scripting is reusability and if any need of modification, you need to modify at one place and it gets reflected in all the other places. Its the best practice to do also.
Reference Qualifiers - ServiceNow Wiki
So in your case -
In the reference field's reference qualifier write the below code -
javascript:UserUtil.getDepartmentUsers();
Create a new script include:
var UserUtil = Class.create();
UserUtil.prototype = {
initialize: function() {
},
getDepartmentUsers:function(){
var usersList = "sys_idIN";
var grUser = new GlideRecord('sys_user');
grUser.addQuery('company',gs.getUser().getCompanyID());
grUser.addQuery('department',gs.getUser().getDepartmentID());
grUser.query();
while(grUser.next()){
usersList = usersList + ','+grUser.sys_id;
}
},
type: 'UserUtil'
};
Mark if it is helpful or correct, feedback is appreciated

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2016 06:16 AM
Hi Mike,
Give this line in your reference qualifier.
javascript: gs.getUser().getDepartmentID()
Regards,
Harish Murikinati.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2016 03:48 AM
Thanks for your help, this worked well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2016 06:28 AM
Hi Mike,
It is good and easy to use the filtered conditions like above, but it is usually good to go for a script include and function in the reference qualifier - in the condition.
The most important advantage of this kind of scripting is reusability and if any need of modification, you need to modify at one place and it gets reflected in all the other places. Its the best practice to do also.
Reference Qualifiers - ServiceNow Wiki
So in your case -
In the reference field's reference qualifier write the below code -
javascript:UserUtil.getDepartmentUsers();
Create a new script include:
var UserUtil = Class.create();
UserUtil.prototype = {
initialize: function() {
},
getDepartmentUsers:function(){
var usersList = "sys_idIN";
var grUser = new GlideRecord('sys_user');
grUser.addQuery('company',gs.getUser().getCompanyID());
grUser.addQuery('department',gs.getUser().getDepartmentID());
grUser.query();
while(grUser.next()){
usersList = usersList + ','+grUser.sys_id;
}
},
type: 'UserUtil'
};
Mark if it is helpful or correct, feedback is appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2016 03:47 AM
Thanks for the help, this worked well