- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 01:51 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 03:43 AM - edited 11-30-2022 03:46 AM
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()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 02:17 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 02:24 AM
Hi @Kalyani Jangam1 ,
Thanks for your reply, I get parsing error: unexpected token from the script include. What does it mean?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 02:35 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 02:36 AM
Hello @JordyZ
Please see attached screenshot
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!