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

Kalyani Jangam1
Mega Sage
Mega Sage

Hi @JordyZ 

Please try below code

In variable reference qualifier use advance and call below script include and its function

javascript: new Validation().checkUser();// Validation is SI name

 

use below code

checkUser: function() {
var answer = [];
gs.addInfoMessage("Script include calls");
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", gs.getUserID());
gr.query();
if (gr.next()) {
gs.addInfoMessage("location---" + gr.location);
var grp = new GlideRecord("sys_user");
grp.addQuery("location", gr.location);
grp.query();
while (grp.next()) {
gs.addInfoMessage("rowcount---" + grp.getRowCount());
answer.push(grp.sys_id.toString());

}
}
return 'sys_idIN' + answer;
},

 

Please try and it will help you.

Please mark correct answer if it will help you.

Hi @Kalyani Jangam1 ,

 

Thanks for your reply, I get parsing error: unexpected token from the script include. What does it mean?

Hi @JordyZ 

Is any other function include in SI. If it is another then  complete with }, and start your function. If still not issue resolved then give full SI code.

Hello @JordyZ 

Please see attached screenshot

Mayuri11_0-1669804441953.png

 

IN your script include those lines are missing. They automatically populates when you create new script include. Please mark your client callable checkbox to true.

After 2nd line you can insert above code.

 

Please mark my response as Correct / Helpful based on Impact.

Thanks!