- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 11:06 PM
Is there any way to evaluate whether a user meets a user criteria inside code (Such as a custom Script Include)?
I have found GlideappCatalogItem & GlideappCategory that can evaluate if something's visible, but they're java classes so I can't see what's under the hood. What I'd really love to be able to do is take a user_criteria & get back a true/false for the current user.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 10:07 AM
You can return a list of user criteria records the the logged in user matches sever side using:
SNC.UserCriteriaLoader.getAllUserCriteria()
I created a script include to return the sys_id of a user criteria record to do the test:
getUserCritera_name(
"name_of_user_criteria_record")
I use this as a condition:
SNC.UserCriteriaLoader.getAllUserCriteria().indexOf(getUserCritera_name(
"Users at Corporate Locations"
)) > -1
I'm currently working on a script include to evaluate client side as well as against any user sys_id not just the logged in user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 06:08 PM
Thanks, that's exactly what I was after! I'd already given up on this and implemented a less advanced user criteria of my own.
Shame it's not documented anywhere. I'm always nervous to use API's like that. Especially when by it's very nature a whole pile of other things will become dependent on it & given it's not a documented API there's no real reason to think it'll keep working in new versions...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 06:35 AM
Hey Robert, first of all thanks for the really helpful information. How did you get this info? Asked via HI-Portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 08:07 AM
I had posted my question in the Community and get a response from Chuck from ServiceNow..
How to use User Criteria as a condition in a script
FYI: I'm almost complete with a script include that will compare any user (not just logged in user) to user criteria. When complete I will post in the above conversation. I want to put it through the paces first.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 08:14 AM
Ah okay nice looking forward to your solution, currently I have solved it with impersonating the user.
evalUserCriteria: function(userCriteriaSysId, userSysId) {
if(userSysId) {
gs.getSession().impersonate(userSysId);
}
return SNC.UserCriteriaLoader.getAllUserCriteria().indexOf(userCriteriaSysId) > -1;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2017 08:20 AM
Thanks Martin,
I might like your solution better. I'll run it by my team.