User Criteria - Can you test this manually?

tim_schneider
Tera Contributor

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.

1 ACCEPTED SOLUTION

rlatorre
Kilo Sage

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.


View solution in original post

13 REPLIES 13

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...


Hey Robert, first of all thanks for the really helpful information. How did you get this info? Asked via HI-Portal?


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.


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;


}


Thanks Martin,


I might like your solution better. I'll run it by my team.