Reference Country Code from a User profile in a script

byronwilkinson
ServiceNow Employee
ServiceNow Employee

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

find_real_file.png

7 REPLIES 7

HI,


After investigation i have one script for you:

 

var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUserID());
gr.query();
if(gr.next())
{
if(gr.country == 'GB' || gr.country == 'FR')
{
answer= true;
}
else{
answer= false;
}

}
else
{
answer= false;
}


Thanks,
Ashutosh Munot

 

Please Hit Correct, Helpful or like,if you are satisfied with this response.

Hi,

Can you close this thread.


Thanks,
Ashutosh

Ashutosh Munot1
Kilo Patron
Kilo Patron

For me this works Like a PRO.... Try this code and let me know.

Thanks,
Ashutosh