Get logged in User's country

sreedharkaliset
Mega Expert

Hi,

I am able to get the location of logged in User but I am not able to get the country. Please help.

gs.getUser().getLocation(); is working
gs.getUser().getLocation().country; is not working

Regards,

Sreedhar

10 REPLIES 10

sreedharkaliset
Mega Expert

Hi All,

Thanks for your reply.

I am trying to find a way to implement this without using a script include. Please let me know if there is an OOB function that could help me achieve this.

Regards,

Sreedhar

Hi 

You can try the script suggested above by me in your script include.

 

Regards,

Omkar Mone.

www.dxsherpa.com

You cannot get the country value directly. in that case you need to have country field in the user table. Then you can retrieve it.you cannot dot walk inside a reference field

 

https://www.servicenowguru.com/scripting/user-object-cheat-sheet/

Regards
Harish

MAX17
Tera Contributor

javascript:GlideLocale.get().getCurrent().getCountry()

Hi

Here is an updated Script:

var user = new GlideRecord("sys_user");
user.addQuery("sys_id", gs.getUserID());
user.setLimit(1)
user.query();
if (user.next()) {
  gs.info(user.name);
  gs.info(user.getDisplayValue("location"));
  gs.info(user.location.country);
}

If the script returns an empty result, your "Location" record does not have any "Country" value set.

BR

Dirk