- 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-22-2016 03:55 AM
Hi Mike,
If the answer solved your issue, could you please mark the answer has correct to help the future users of community,
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2018 04:35 AM
Is it possible to filter the reference filed based on the current loggedin user role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2020 09:54 AM
Well instead of creating the script include and then calling it from the reference qualifier.
I would suggest to add this in reference qualifier and you can active if you want to include inactive users aswell
javascript:'active=true^department='+gs.getUser().getDepartmentID();