Populate the Logged in Users location in condition builder

kmishra76k
Tera Expert

Hi,

I want the location of logged in user in below condition builder:

find_real_file.png

For this I have used following script:

1. javascript:gs.getUser().getRecord().getDisplayValue('location'); >> It is showing error "Error Message

Illegal access to method getRecord() in class com.glide.sys.User"
 
2. javascript:gs.getUser().getLocation();  >> it is giving me sys_id but I want value. I have used toString() also but no luck.
 
3. Using Script Include: 
function myLocation1(){
var location = gs.getUser().getRecord().getDisplayValue('location');

return location;
}
 
javascript:myLocation1();  >> It is showing NULL value.
 
 
Could anyone please  help me out. 
 
My main purpose is to populate logged in user's Location.
 
Your attention to this is highly appreaciable.
 
Regards,
Keyur

 

3 REPLIES 3

Rahul Singh8
ServiceNow Employee
ServiceNow Employee

Hi,

 

You can use dynamic filter as shown in the attached screenshot.

 

Thanks

Rahul

bishopx
Giga Guru

Hello Keyur,

 

You can use something like this:

javascript: gs.getUser().getLocation()

Gaurav Bajaj
Kilo Sage

Hi,

Are you looking for the location of logged in user or his country name in your condition?

 

If you are using display value, then you will get location's name and not the country which is why you won't get anything.

If you are looking for the country only, then you might want to change the script include to point out the country and return it.

function myLocation1(){
var gr = new GlideRecord("sys_user");
gr.get(gs.getUserID());
var country=gr.location.country;

return country;
}

 

Please mark it correct/helpful based on the response.

Thanks
Gaurav