User criteria script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2025 02:00 PM
Hi, I am trying to create a user criteria to check the user's state using a script. I noticed that in sys_user there is a reference field called location.parent pointing to the cmn_location table. I don’t know how to do this dot walk. I also noticed that when opening the record in the cmn_location table, the field that contains the value I want is name.
this is the script i build:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2025 02:49 PM
HI @LucasEduarF ,
Please find the adjusted script:
function checkCondition() {
var user = new GlideRecord('sys_user');
if (user.get(gs.getUserID())) {
// Dot-walk to location.parent.name
var parentName = user.location.name.toString(); // for user location name (user.location.parent.name;- if you want access location parent name)
if (parentName == 'PE') { //the name of your location
return true;
}
}
return false;
}
Please mark this as helpful and correct if this helps you.
Thanks,
Yaswanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2025 11:19 PM
Hi @LucasEduarF
Try the below script in your user criteria record.
var user_id = gs.getUserID();
var user_rec = new GlideRecord('sys_user');
user_rec.get(user_id);
var loc = user_rec.location.name;
if (gs.nil(loc)){
answer = false;
}else{
if(loc == 'SHS quadra 5, Bloco E., Brasilia'){ //UPDATE THE NAME AS REQUIRED
answer = true;
}else{
answer = false;
}
}
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2025 01:46 AM
hi @LucasEduarF
answer = false;
var user_rec = new GlideRecord('sys_user');
user_rec.addQuery('sys_id',user_id);
user_rec.addQuery('location.name', 'PE');
user_rec.query()
if(user_rec.hasNext()){
answer = true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2025 05:27 AM
try this
var user_rec = new GlideRecord('sys_user');
user_rec.addQuery('sys_id', user_id);
user_rec.addQuery('location.name', 'PE');
user_rec.query();
answer = user_rec.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