Using reference qualifier to filter users based on the current user's location

JordyZ
Mega Sage

Hi, I have a variable on a catalogue item that references the sys_user table. I'd like that variable to only show the users that are in the same location as the current user's location (i.e current user is European so he will only see European users). How do I do this with reference qualifier?

 

I've found a post that resembles this problem, but not entirely. I'm new to ServiceNow, so I don't know yet how to tweak the answer to fit my specific case.

 

https://www.servicenow.com/community/it-service-management-forum/reference-qualifier-to-filter-locat...

1 ACCEPTED SOLUTION

Rebecca3
Tera Guru

There is a much easier way to do this, without requiring a script include. 

gs.getUser().getLocation() returns the location of the logged in user. In the reference qualifier of your variable, you can use it as follows -

 javascript:gs.getUser().getLocation()

Rebecca3_2-1669808649231.png

 

Rebecca3_1-1669808506108.png

 

View solution in original post

14 REPLIES 14

Rebecca3
Tera Guru

There is a much easier way to do this, without requiring a script include. 

gs.getUser().getLocation() returns the location of the logged in user. In the reference qualifier of your variable, you can use it as follows -

 javascript:gs.getUser().getLocation()

Rebecca3_2-1669808649231.png

 

Rebecca3_1-1669808506108.png

 

Hello @Rebecca3 ,

 

Thanks for your reply. When I try this, and test the variable, no caller comes up. My user has location set as Brussels-Belgium, I'd like it to show all users from Europe. Any tips?

Hi Jordy,

You mentioned the same location so I assumed the value in the location field would be the same - are you currently storing somewhere which locations are in Europe?

 

Hey @Rebecca3 ,

Yes it is stored somewhere but I'm not sure where to find it, I will get back to you once I do.

 

In the meanwhile I tried the solution you've provided above for same location, I'm not sure what went wrong but even if I set my location to the same as another user, I don't see that user when I test the variable.

Hi @Rebecca3 , 

 

This is what I was able to find out about the region. "region and country are stored in the location table with a parent child link. For the filter on the location of the connected user, it's the region (but the region is stored in the location field of the user) So user from a region see only users from his region."