User criteria to restrict by country shown in user location
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2017 05:48 AM
How would I format a script to restrict to a location's country value based on a users location record.
I am using Country to limit who can see certain things in the Service Catalog, and having trouble getting it to pull the right info.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2017 01:28 AM
Hi,
This script can be used as a User Criteria to validate the country of the user's location.
Country('Australia');
function Country(country) {
var retVal;
var usr = new GlideRecord('sys_user');
usr.get(gs.getUserID());
if (usr.location.country == country) {
retVal = true;
} else {
retVal = false;
}
return retVal;
}
Regards
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2020 02:09 AM
Hello,
I find this helpful. How should I modify the script, if I need to set more than 1 country?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2020 12:51 PM
Hi,
There are different ways to accomplish that but for 2 countries it could be done like this.
Country('Australia','China');
function Country(country,country2) {
var retVal;
var usr = new GlideRecord('sys_user');
usr.get(gs.getUserID());
if (usr.location.country == country || country2) {
retVal = true;
} else {
retVal = false;
}
return retVal;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2017 01:49 AM
Hi Shembop,
You can also try this
answer = false;
var logUser = gs.getUserID();
var gr1 = new GlideRecord('sys_user');
gr1.addQuery('sys_id',logUser);
gr1.query();
if (gr1.next())
{
if (gr1.location.country == "India"){
return true;
}
else {
return false;
}
}
Mark it as answered How to Mark Answers Correct From Inbox View