- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2019 07:15 AM
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?
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2019 02:28 AM
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()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2019 07:44 AM
Hi,
You should create a script include function that you will call to retrieve the country passing the user's location in parameter.
Regards

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2019 07:47 AM
Hi,
You can create script include , client callable true
Here i created
Script include name : UserObjectUtils
var UserObjectUtils = Class.create();
UserObjectUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCountry: function() {
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", gs.getUserID());
user.setLimit(1)
user.query();
if (user.next()) {
return user.getValue("please provide country variable name here");
}
},
type: 'UserObjectUtils'
});
Your refernce qualifier is javascript:new UserObjectUtils().getCountry()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2019 07:03 AM
Thanks for helping Harish. This script retrieves the 'Country' field from the sys_user table.
However I require the country field that is available on the location table 'cmn_location'.
How would I retrieve this value, as I can't seem to dot-walk here?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2019 02:28 AM
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()