- 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 12:49 PM
running the script that you provided, it returned departments with at least one user in it. however the qualifier code returned departments that did not have any user in them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 12:57 PM
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; } - needed to remove : from your example and changed it to ":" and the code worked. thanks alot.