- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Hello,
I have a user criteria set with location as 'north america'. Canada and mexico are locations with parent as north america. But the users from canada and mexico are not getting included in the criteria. I need a script to include them. Can you assist me with this please.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago - last edited 4 hours ago
Hi @SarahM584850592 ,
By default, user criteria doesn’t automatically include child locations when you set a parent location. To include Canada and Mexico, you’ll need to extend the user criteria with a script.
Example approach:
Create a Scripted User Criteria.
Add logic to check the user’s location and also the parent location.
Sample script:
(function() {
var user = gs.getUser();
var location = new GlideRecord('cmn_location');
if (location.get(user.getLocation())) {
// Direct match
if (location.name == 'North America')
return true;
// Check parent location
if (location.parent && location.parent.name == 'North America')
return true;
}
return false;
})();
This way, users in "North America" and its child locations (Canada, Mexico) will meet the criteria.
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
that's OOTB behavior.
You will have to get logged in user country and compare it with those 3
You can use Advanced Script like this
Note: It's recommended to use user_id instead of gs.getUserID() in user criteria script
user_id variable usage for user criteria
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", user_id);
gr.addQuery("location.name", "IN", "Canada,Mexico,North America"); // give correct location name here
answer = gr.hasNext();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader