- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 08:34 AM
catalog item --> reference field --> cmn_department --> how to only show departments where the users tab have member(s) in it? is there a way to filter the cmn_department so that it only shows department where there are user in the users tab?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 09:42 AM - edited 05-02-2024 09:43 AM
@UIH_SN_dev01 You need to use the following reference qualifier on your Department variable on the catalog item.
Here is the reference qualifier code.
javascript:getDepartmentWithUsers(); function getDepartmentWithUsers(){ var userDept = new GlideRecord('cmn_department'); userDept.addJoinQuery('sys_user','sys_id','department'); userDept.query(); var refQual = 'sys_idIN'; while(userDept.next()){ refQual = refQual+userDept.sys_id+','; } return refQual; }
Please consider marking the answer correct and helpful if it manages to address your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 08:45 AM
Hi @UIH_SN_dev01 ,
Go to the sys_user table and investigate if there isn't a reference field relating to cmn_department.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 09:42 AM - edited 05-02-2024 09:43 AM
@UIH_SN_dev01 You need to use the following reference qualifier on your Department variable on the catalog item.
Here is the reference qualifier code.
javascript:getDepartmentWithUsers(); function getDepartmentWithUsers(){ var userDept = new GlideRecord('cmn_department'); userDept.addJoinQuery('sys_user','sys_id','department'); userDept.query(); var refQual = 'sys_idIN'; while(userDept.next()){ refQual = refQual+userDept.sys_id+','; } return refQual; }
Please consider marking the answer correct and helpful if it manages to address your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 10:28 AM
thank you for the help. i tried the code but it is still bringing back departments where there are no users in them.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 11:12 AM
@UIH_SN_dev01 I already tested this code on my instance and it only fetches the department with the users.
Could you please run the following code in a background script on your instance and check it it prints the name of those departments where there is at least one user.
getDepartmentWithUsers();
function getDepartmentWithUsers()
{
var userDept = new GlideRecord('cmn_department');
userDept.addJoinQuery('sys_user','sys_id','department');
userDept.query();
while(userDept.next())
{
gs.info(userDept.name);
}
}