The catalog item should not be visible to the specific countries.

Archana23
Tera Contributor

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.

1 ACCEPTED SOLUTION

Riya Verma
Kilo Sage
Kilo Sage

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
  }
})();
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

View solution in original post

8 REPLIES 8

Peter Bodelier
Giga Sage

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.

I have tried with the same..It is not working as expected..So please suggest me in the script.

Ankur Bawiskar
Tera Patron
Tera Patron

@Archana23 

can you share your user criteria screenshot

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Archana23_0-1687771243231.png

Archana23_1-1687771325076.png

 

 

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.