- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 08:20 AM
The specific catalog item should not be visible for the Mexico, Panama, Dominican Republic , Trinidad & Tobago, Colombia, Venezuela, Peru, Ecuador, Brazil, Bolivia, Uruguay, Chile and Argentina countries. I need help in the user criteria script.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 02:46 AM
Hi @Archana23 ,,
Hope you are doing great.
Please try using below script in user criteria:
(function () {
// Get the country of the user making the request
var country = gs.getUser().getCompany().getCountry();
// Define the list of countries where the catalog item should be hidden
var hiddenCountries = [
'Mexico',
'Panama',
'Dominican Republic',
'Trinidad & Tobago',
'Colombia',
'Venezuela',
'Peru',
'Ecuador',
'Brazil',
'Bolivia',
'Uruguay',
'Chile',
'Argentina'
];
// Check if the user's country is in the list of hidden countries
if (hiddenCountries.indexOf(country) !== -1) {
return false; // Hide the catalog item
} else {
return true; // Show the catalog item
}
})();
Regards,
Riya Verma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 08:33 AM
Hi @Archana23 ,
It is not needed to script here.
Please follow this documentation, to extend your User Criteria which enables you to filter on Country, the same way as you can do on for example groups or roles.
Kind regards,
Peter Bodelier
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 02:06 AM
I have tried with the same..It is not working as expected..So please suggest me in the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 02:18 AM
can you share your user criteria screenshot
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 02:22 AM
var location_sys_id = '';
var user_id = gs.getUserID();
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', user_id);
user.query();
if (user.next()) {
location_sys_id = user.location;
}
var final_parent = '';
do {
var loc = new GlideRecord('cmn_location');
loc.addQuery('sys_id', location_sys_id);
loc.query();
if (loc.next()) {
var parentloc = loc.parent; // returns parent sysid
var parentname = loc.getDisplayValue('parent');
var userlocname = loc.name; // returns parent name
location_type = loc.cmn_location_type;
if (location_type == 'region') {
final_parent = loc.sys_id;
break;
}
}
final_parent = loc.parent;
}
while (parentname == userlocname);
var ans1 = false;
var prop = gs.getProperty();
if (final_parent == 'SE_Storing the locations') {
ans1 = true;
}
answer = ans1;
I have used this script too..I have tested for adding the 4 locations..Anyhow this not working as expected.