Catalog user Criteria
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2024 05:22 AM
Hi All,
I have been asked a question in the Interview : How I can restrict the Catalog Item for the users which are from 'America' location?
I answered like we can restrict it through the user criteria via location field.
Then the next counter question was suppose i want to script it then how can you achieve it?
Can someone please help me how to restrict via script in User criteria?
Thanks,
Rooma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2024 05:27 AM
Hey,
Check this thread out - https://www.servicenow.com/community/itsm-forum/how-to-restrict-catalog-item-for-user-country/td-p/7...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2024 06:02 AM
Hi,
Not sure if the counter question is a trick question. Why would you want to script a user criteria if it can be done via setting the location field?
It can be done, and I believe the best way would be to do it by calling a script include, that returns true if the user is located in 'America'.
Then the user criteria script would look something like this:
// passing user_id to the function will contain the logged in users UserID.
answer = new YourScriptIncludeName().yourFunctionName(user_id);
// the script include would be kind of simple too, something like this:
yourFunctionName: function(userId){
var userGR = new GlideRecord('sys_user');
if (userGR.get(userId){
if (/*your condition to find out if the user has America location*/){
return true;
}
else{
return false;
}
}
else{
// user not found
return false;
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2024 07:58 AM
Hi @Rooma1
The first way is User criteria only which is no code / low code way. You can restrict via Script but only when you did not find way in OOTB way.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************