- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 10:38 PM
Hi All,
Requirement: I have one record producer which I want give the access for only those user which country should be Argentina ,Brazil, Colombia, Mexico in their profile i.e location.country so how we can add in available for to restrict the access for other country except above four country.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 03:32 AM
Hi @rmaroti I have updated the code as below
Let me know if this works
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 11:16 PM
Hi @rmaroti
You can use the below script in the advanced part script in the Available for User Criteria.
1. Create a user criteria & add the condition in it
checkCondition();
function checkCondition() {
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
// Define the allowed countries
var allowedCountries = ["Argentina", "Brazil", "Colombia", "Mexico"];
// Check if the user's country is in the allowed list
if (user.isValidRecord() && allowedCountries.includes(user.location.country)) {
// User's country is allowed, so return true to grant access
return true;
} else {
// User's country is not allowed, so return false to deny access
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 02:46 AM
hi @Sohithanjan G - when I use the above code allowed country users also not accessible the record producer.
plz find attached screenshot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 03:26 AM
Hi @rmaroti ,
Add toString()
updated code. its working for me well.
checkCondition();
function checkCondition() {
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
// Define the allowed countries
var allowedCountries = ["Argentina", "Brazil", "Colombia", "Mexico"];
// Check if the user's country is in the allowed list
if (user.isValidRecord() && allowedCountries.includes(user.location.country.toString())) {
// User's country is allowed, so return true to grant access
return true;
} else {
// User's country is not allowed, so return false to deny access
return false;
}
}
🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 11:21 PM
Hi @rmaroti you would need to create a User Criteria and check if user is part of the country specified and return true.Add this user criteria to the record producer related list under Available For
Script:
var userSysId = gs.getUserID(); // get current user sys_id
var userGr = new GlideRecord('sys_user');
if (userGr.get(userSysId)) {
var userCountry = userGr.location.country; // get user's country
if (userCountry == 'Argentina' || userCountry == 'Brazil' || userCountry == 'Colombia' || userCountry == 'Mexico') {
return true;
} else {
return false;
}
}
Harish