User criteria on a reference field ?

shanmupriya
Kilo Contributor

We have Test Catalog Item "Order a Laptop" -> were a reference field "Requested For" - "sys_user".  

Field 1: Requester --> Satisfies specific User Criteria'

Filed 2: Requester For --> We need a filter for the users only who satisfy the user criteria same as Requester

So the Data populated in the Requested For field should populate the users only who satisfy the User criteria same as the logged-in user.

Could somebody help?



1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@shanmupriya 

you can get all user criterias which are satisfied by that user selected in Requester variable using User Criteria Loader API

UserCriteriaLoader - API to Evaluate User Criteria

Steps to be used in script include

1) get user criterias satisfied by logged in user using -> getAllUserCriteria

2) then query sys_user table and for each user check if user matches any of the above listed user criterias

3) return that array of users in advanced ref qualifier

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Hi @Ankur Bawiskar 

Thanks for your response. The suggested solution works perfectly fine, But I guess one major check is missing. With the filter conditions given, it filters the users who matches at least one of the User Criteria same as the logged-in User.

I Would like to know is there a way to check/filter the users who originally satisfy the user criteria for this specific catalog item?

So lets say, If user ABC profile has 5 user criteria and user xyz has 1 user citeria
Now with this script, if 1 has a match, then the user XYZ is getting listed on the Requested For.

Can we check if the XYZ user satisfies this catalog item's User Criteria as well?

 
 

Hi,

you can try to explore on that User Criteria Loader API

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

 

Below are additional Knowledge articles which discusses Semaphore Exhaustion caused by the getAllUserCriteria function being called in widgets:

 

Semaphore Exhaustion is caused due to the getAllUserCriteria function getting called in widgets

Semaphores keep getting stuck and cause slow performance due to UserCriteriaLoader.getAllUserCriteri...