User Criteria script not triggering debugger or running
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2023 06:10 PM
Hey all, i've been struggling with user criteria for the past week. i've created a mock function to practice creating user criteria scripts.
No matter what I do, my script does not run. User criteria scripts are not cached so it looks like they run each time.
it SHOULD be running
But, when do they run?
when a user clicks on self service > knowledge?
when a user opens an article?
I've tested every scenario and my user criteria script simply does not run. The debugger does not trigger and I don't know what's going on
here is my function.
// Get the user's groups
var userGroups = new GlideRecord('sys_user_grmember');
userGroups.addQuery('user', user_id);
userGroups.query();
// Check if the user belongs to the TEST group
var answer = false;
while (userGroups.next()) {
var group = userGroups.group.getRefRecord();
if (group.type == 'TEST') {
answer = true;
break;
}
}
return answer;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2023 03:13 AM
For starters you might just want to log what you're doing.
For example in this script you're using user_id, but is it a variable that you've defined?
I'd start by adding logs like
gs.info("User criteria user id: " + user_id);
gs.info("User criteria grmember count: " + userGroups.getRowCount());
and
gs.info("User criteria valid group: " + group.isValidRecord());
That way you can check the logs, see that something is running and see the actual values there.
Also, you're now checking that type == "TEST"
The type field contains a comma separated list of sys_ids, so you'd have to compare it to the sys_id of TEST.
If you have more than one type, you'll probably also need to use something like type.indecOf("TEST sysID") > -1 as your condition to check if the sys_id is included.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2023 11:50 AM
Shouldn't the debugger still be running tho? user criteria is evaluated each time, i set my breakpoints and it doesn't run.
Where do the gs.info logs print to?
the user_id is a variable that is already instantiated within a user script.
I'm still fairly new to servicenow and i hate not being able to use the
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2023 12:00 AM
I must admit that I haven't fully utilized the debugging tools, since I generally just log stuff first, so I'm not sure if you're even using the correct debugging tool.
Logs show up in "syslog" table.
It's under "System Logs" -> "System Log" -> "All"
If you can see your logged values there then it's running OK.
Make sure to always use filter "Created on today" since there's a lot of data in the log table and it might otherwise take a while to load. You can include "Message starts with User criteria" to get your logs.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2023 05:40 AM - edited ‎03-19-2023 05:42 AM
HI @kgomez222 ,
Try below script:
// Get the user's groups
var userGroups = new GlideRecord('sys_user_grmember');
userGroups.addQuery('user', user_id);
userGroups.query();
// Check if the user belongs to the TEST group
var answer = false;
while (userGroups.next()) {
var group = userGroups.group.getRefRecord();
grpType = group.type;
if (grpType.indexOf('sys_id_of_the_group_type') > -1) {// look for the sys_id in the "sys_user_group_type" table
answer = true;
break;
}
}
return answer;
Aman Kumar