Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Reference Qualifier to filter locations based on User Location

mattfollowell
Tera Expert

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%.

1 ACCEPTED SOLUTION

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();

View solution in original post

39 REPLIES 39

Here is the log after I changed the ref qualifier:

 

org.mozilla.javascript.EcmaError: undefined is not a function.
   Caused by error in <refname> at line 1

==>   1: new getLocation.locations();

Hmmm did you do:

javascript:new getLocation.locations();

or

javascript:new getLocation().locations();

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

LinkedIn

I edited my original comment a few minutes after I posted it, sorry for the typo.

Hey! After updating the reference qualifier to include both () log output is this:

DEBUG: AL /

That's something.

Where are you getting that log from? That shouldn't come from the code above unless you've added something. Is the reference qualifier working now?