Reference Country Code from a User profile in a script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2018 05:34 AM
We're trying to amend a script that was using the sys id of the domain to determine whether a user from different domains can see various things. This is current and works:
var Remote = Class.create();
Remote.prototype = {
initialize: function() {
},
domID: function() {
var userObj = gs.getUser().getDomainID();
if(userObj == "8715208d375c41728366542518276g52")
return true;
},
type: 'Remote'
};
But we want to amend this to look at the users' country code entry instead, so we've attempted a few options and this is what I thought it would be but its not working. The country code is showing on the user profile in the OOTB country field as a choice from a list
var Remotec = Class.create();
Remote.prototype = {
initialize: function() {
},
domID: function() {
var userObj = gs.getUser().getCountry();
if(userObj == "GB")
return true;
},
type: 'Remote'
};
Can anyone suggest what would be required to reference the country code field from the user profile?
Ive tried variations on getCountry like getcountry, sys_id.country etc, but nothing is working so far. Country field showing below

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2018 05:52 AM
HI,
Country Code is different and Country is different.
There is nothing like this: gs.getUser().getCountry();
There is something like this : gs.getUser().getCountryID();
Can you GlideRecord to user table and get country code as below:
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUser());
gr.query();
if(gr.next())
{
if(gr.country == 'GB')
return true;
}
Thanks,
Ashutosh Munot

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2018 06:32 AM
Thanks but thats not worked (tried in User Criteria script and also in a Script Includes as we have the same challenge in both). Im wondering if we can actually reference the country field in this way. The User criteria script is looking to allow catalog access only for those with Country Code of GB or others. We may try with groups but there are so many users. For the script include its a script thats determine when some javascript should run on a service portal widget. I would of thought once we have one working script, it would apply to both.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2018 10:48 PM
Do you want to hide a catalog item for specific user or country code?
Thanks,
Ashutosh Munot

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2018 12:58 AM
We want the user criteria to define access to a category. And we're trying to add a script within the user criteria to state that if the user has a country code of 'GB' or 'FR' etc, then the user criteria should run