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

Martin,


We use impersonate in some integrations and we revert back to system. Would this be necessary for this application?


logger.logDebug('onAfter processing - Turn off Impersonation.   Going back to \"system\"', null, null);


gs.getSession.impersonate('system');


Hello Robert,



I'm not sure, but I think it will do no harm so I would revert back to system just in case.


This solution is what I've been doing for awhile now, but have come to find out that it fails if executed as a user who does not have the impersonator or admin role.

Use case: our Service Desk is trying to view catalog items that are available for their current caller. My script include impersonates the caller, runs through the catalog and determines what they have access to. It works fine if an admin or user with the impersonator role tries this, but the Service Desk does not have these roles.

 

Any ideas on how to impersonate server-side regardless of the logged in user's permissions?

johnmark
ServiceNow Employee
ServiceNow Employee

UserCriteriaLoader.getAllUserCriteria() method is a deprecated method and we advice using userMatches() instead.

☞ Please refer to this article below, which explains on this in detailed.
https://www.servicenow.com/community/now-platform-blog/a-deep-dive-to-user-criteria/ba-p/2281285