- 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:06 AM
I think it was somehow cached in my browser, because I cleared my cache and reloaded the form.
Here's the error now:
Invalid query detected, please check logs for details [Unknown field null in table cmn_location]

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 09:09 AM
Don't see it. Maybe I'm missing something. Might this already be an excisting error you are getting? If you clear the advanced reference qualifier and try again, are you still getting that error? If so... it's comming from something else that doesn't have anything to do with this.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
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:15 AM
I agree with Mark, I'm not sure where the error is coming from with these scripts. Did you check your logs and see if any other errors exist?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 09:18 AM
Yeah I am at a loss, I cleared out the reference qualifier all together and no error when the form loaded.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2020 09:26 AM