- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 07:11 AM
I have a variable on a catalogue item that references the locations table. I want that variable to only list locations whose parent = the signed in user's location. EXCEPT if the signed in User's location = MG. If the signed in user's location is MG then I want the variable to list all locations on the table.
function advloc() {
var locPar;
var userLoc='';
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUserID());
gr.query();
while(gr.next()){
userLoc=gr.location;
}
if(userLoc.includes("MG")){
locPar = "";
}
else {
locPar = "parent = userLoc";
}
return locPar
}
I think it is not working because it returns the name of the location and not the Sys_Id, but I'm not 100%.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 07:39 AM
You're on the right track. That script belongs in a script include that is client callable:
And in your reference qualifier you would just do:
new getLocation().locations();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 09:53 AM
Mark asked that I added. "gs.info('DEBUG: ' + gr.location.getDisplayValue() + ' / ' + locaPar);"
For Debugging.
And unfortunately not. 😕
Even when I remove the debug text it still does not work.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 09:52 AM
Ah oke, so the location is "AL"?
Only somehow locPar is not written to the logs... (or I made a typo when asking to add logging... because I wrote locaPar... an a to many! my mistake)
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 09:54 AM
Yes, the user I am testing with has the Location of AL. I'm trying to see if the "else" applies.
Lol, don't worry I caught your typo and changed it when I added it to the script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 10:02 AM
Ah oke. You could add debugging to both the if and the else, to see which is reached.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 10:02 AM
It seems like it is working. AL doesn't have MG in it so the location should be "".