- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2024 12:17 PM
Hi, this is my script
(function() {
var userId = gs.getUserID();
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', userId);
gr.query();
if (gr.next()) {
if (gr.u_region == 'AMER') {
return true;
} else {
return false;
}
} else {
return false;
}
})();
not sure why it is not working. Please check and tell.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2024 01:18 AM
(function() {
var userId = gs.getUserID();
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', userId);
gr.query();
if (gr.next()) {
if (gr.u_region == 'AMER') {
return true;
} else {
return false;
}
} else {
return false;
}
})();
this is working, thank you for the assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2024 01:20 PM
Please explain complete requirement, what you are trying to achieve for better understanding. But for now i suggest
To ensure that u_region is the correct field name,
custom field names usually start with ‘u_’,
The comparison in if (gr.u_region == 'AMER') is case-sensitive. Ensure that the value stored in the database is exactly ‘AMER’ in all uppercase letters. If there’s a possibility of mixed case values like ‘Amer’ or ‘amer’, consider using a case-insensitive comparison:
if (gr.u_region.toUpperCase() == ‘AMER’)
You can use gs.info(), gs.warn(), or gs.error() for debugging:
Please mark it helpful and accepted if this helps you in somehow. This will help both community and me.
Thanks and Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2024 12:41 AM
Hi Deepak, My script worked on the background scripts but when added to User criteria it is not allowing any Region users except admins.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2024 01:18 AM
(function() {
var userId = gs.getUserID();
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', userId);
gr.query();
if (gr.next()) {
if (gr.u_region == 'AMER') {
return true;
} else {
return false;
}
} else {
return false;
}
})();
this is working, thank you for the assistance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2024 01:13 AM
@Rahul Raja Sami Could you please update your script as follows and see if it works.
(function() {
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', user_id); //user_id is a global variable available in user criteria.
gr.query();
if (gr.next()) {
if (gr.u_region == 'AMER') {
return true;
} else {
return false;
}
} else {
return false;
}
})();
Here user_id is a global variable available in user criteria. For more information please refer to https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0780775