- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 01:54 AM
Hi All,
Actually i have one reference field "Business", it refers to Department table, now i need a reference qualifier that i need Department list from user table (from group by department column which are not empty )?
So please help me to achieve this
Thanks
Deepika
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 03:07 AM
got it.
so you want to see only those departments where there is at least some user.
then use this advanced ref qualifier
and invoke it like this
javascript: fetchDepartments()
function fetchDepartments(){
var arr = [];
var gr = new GlideRecord("cmn_department");
gr.query();
while (gr.next()) {
var user = new GlideRecord('sys_user');
user.addQuery('department', gr.getUniqueValue());
user.setLimit(1);
user.query();
if(user.hasNext())
arr.push(gr.getUniqueValue());
}
return 'sys_idIN' + arr.toString();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 02:41 AM
Hey,
Here is the script include for the same:
And put this in your reference qualifier:
javascript:(new global.GetUserDepartments().departmentName())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 02:49 AM
reference field is referring to cmn_department.
Each record in cmn_department will have unique department.
I didn't get your complete requirement.
Can you share with screenshots?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 03:03 AM
Actually Department table has many department list, but i want that the department list which are existing in the user table only ?
Like in the department table it has 1000 departments, but in the user table (under department column), users are assigned to 100 departments only that few users are assigned to same deparment, so i want this list to be pull up for that field
Thanks
Deepika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 03:07 AM
got it.
so you want to see only those departments where there is at least some user.
then use this advanced ref qualifier
and invoke it like this
javascript: fetchDepartments()
function fetchDepartments(){
var arr = [];
var gr = new GlideRecord("cmn_department");
gr.query();
while (gr.next()) {
var user = new GlideRecord('sys_user');
user.addQuery('department', gr.getUniqueValue());
user.setLimit(1);
user.query();
if(user.hasNext())
arr.push(gr.getUniqueValue());
}
return 'sys_idIN' + arr.toString();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 03:40 AM - edited 03-14-2023 03:42 AM
Is this a script include?, actually we have one script include, so do i need to add this code in that?
Thanks
Deepika