I need to create a user criteria with specific departments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 04:43 AM
Hi Team,
I need to create a catalog user criteria with specific department name starts with 'GS'
I need to advanced option.
Please help!
Thanks in advance,
Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 04:50 AM
Hi,
You can write the User criteria Script as below:
answer = checkCondition();
function checkCondition() {
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
var dept = user.dept.name;
if(dept == 'Value' || dept == 'Value')
return true;
else
return false;
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 04:53 AM
In the script above just give the Department value which you want to evaluate and you should be good with your requirement.
Say if there are multiple Department for which you want to check then you can update the script as below:
answer = checkCondition();
function checkCondition() {
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', gs.getUserID());
user.addEncodedQuery('department.nameSTARTSWITHGS'); // Check for Department start with GS
user.query();
if (user.next()) {
return true;
} else {
return false;
}
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 04:57 AM
Hi Sri,
Please could you go through below links:
Apply user criteria to items and categories
http://www.servicenowguru.com/scripting/user-object-cheat-sheet/
Set the condition as per your requirment:
gs.getUser().getRecord().getValue('active') == true
for more info go to advance script options
*** Help with User Criteria Advanced Script
If my answer helps you then please mark my answer is ✅ correct and helpful.
Thanks
Sanjay Bagri
QBrainX Pvt. Ltd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 05:09 AM
Hi Sri,
As per best practice you can use user_id to get logged in user sysId and don't use gs.getUserID()
Use this script
var rec = new GlideRecord('sys_user');
rec.addQuery('sys_id', user_id);
rec.addEncodedQuery('department.nameSTARTSWITHGS');
rec.query();
answer = rec.hasNext();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader