User Criteria Script for catalog item
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 11:55 AM
Hello All
I am working on User Criteria requirement for a Catalog Item.
We have a country field on sys_user table (Note: Country field is reference field type and table is core_country).
I only want users whose country is Brazil to see the catalog item.
How I would be able to script in the Advanced script box of the User Criteria record for this.
I want to filter it for users whose country is Brazil.
Thanks!!
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 12:02 PM
I think you can achieve this without script too. please check below
if you want to use advanced script then it will be something like below.
// Advanced Script to filter users whose country is Brazil
(function() {
// Get the current user's country reference field value
var userCountry = gs.getUser().getRecord().getValue('country');
// Check if the country reference field is pointing to Brazil
if (userCountry) {
var countryGR = new GlideRecord('core_country');
if (countryGR.get(userCountry) && countryGR.name == 'Brazil') {
return true;
}
}
// If the country is not Brazil, return false
return false;
})();