How to create a dynamic filter option for department name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 02:50 AM - edited 11-24-2023 01:32 AM
Hi,
I would like to filter on my Knowlegde Dashboard Authors in the logged-in User's Department. Usually you can use the following oob. script: gs.getUser().getDepartmentID();
Problem: We have Departments with the same Name but different ID's. So that the User of the Dashboard is for e.g probably only able to filter the half of the Authors within his/her Department.
To avoid this problem, how is it possible to filter for the user department name. I tried already this: gs.getUser().getDepartment().name;
So is it possible to create a dynamic filter option against the name (string type) field instead of the sys_id (reference field)?
Thank you for any help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 09:34 PM
Hello @josBak,
Please refer to the below link:
https://www.servicenow.com/community/developer-forum/how-to-create-dynamic-filter-option-for-departm...
Mark my correct and helpful, if it is helpful and please hit the thumbs-up button to mark it as the correct solution.
Thanks & Regards,
Abbas Shaik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 01:36 AM
Hi Abbas,
I saw this post before but it didn't helped me.
Nevertheless thank you for you support. Any other suggestions are highly welcome.
Best regards
Josef

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 02:00 AM
Hi Jos,
You can use script include as below:
var getdepartmentNames = Class.create();
getdepartmentNames.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getdeptforuser: function() {
var deptname = '';
var getdept = new GlideRecord('sys_user');
getdept.addQuery('sys_id', gs.getUserID());
getdept.query();
if (getdept.next()) {
deptname = getdept.department.getDisplayValue();
}
return deptname;
},
type: 'getdepartmentNames'
});
Then use it in the qualifier script field as below
javascript: new getdepartmentNames().getdeptforuser()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 06:18 AM
No, dynamic filters are for fields of type reference.
Very 1st sentence on docs page Create a dynamic filter option.
That said, to me it is not clear what you want to accomplish.
Do you want to filter users to the ones who have already created Knowledge Articles and are in the same department as the current user, or do you want to filter users to the ones who are in the same department as the current user?