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.

How to retrieve the country of the current logged in user?

Victor Rusch
Kilo Contributor

Hello,

I have to pre-fill a field on a record producer with the Country of the person creating the incident.

I tried using javascript:gs.getUser().getLocation(); , however this only returns the location of the user, I require the country field. I tried using different variants on this script but I can't get it to work.

Can anyone help me to achieve this?

1 ACCEPTED SOLUTION

Try now 

Script include name : UserObjectUtils

var UserObjectUtils = Class.create();
UserObjectUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

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

},
type: 'UserObjectUtils'
});

 

Your refernce qualifier is javascript:new UserObjectUtils().getCountry()

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

I need to use the filter in the reporting on incident form.

filter-caller.location.country should be equal to "current logged in user".