We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to get all department list from user table for reference field in catalog item?

Deepika61
Tera Contributor

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

1 ACCEPTED SOLUTION

@Deepika61 

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.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

21 REPLIES 21

Aniket Bhanse
Tera Guru

Hi,

 

Please write your Reference qualifier like this:

javascript:(new global.GetUserDepartments().departmentName())

 

And write your script include like this:

AniketBhanse_0-1678785517824.png

 

 

I hope this helps. Please mark Correct/Helpful if it helps you in any way.

 

Thank you

Deepika61
Tera Contributor

Hi All, 

 

Please help me on this

Thanks

Deepika