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

Mihir Mohanta
Kilo Sage

Print logs by using gs.log() function inside the script and find out script is running perfectly or not.



Thanks,


Mihir


I'm not sure you've understood my question at all... I'm not asking to debug my script. I'm asking if a function within ServiceNOW for evaluating User Criteria (which I presume exists as the platform itself can evaluate it) is accessible to developers on the platform.



Logging won't help me with that.


Aric3
Giga Expert

Hi Tim,



I had a similar question regarding user criteria about a week ago but haven't received any replies.. If I get a response, I'll be sure to update this thread.



Thanks,


Aric


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.