User Criteria on custom table

Ken83
Mega Guru

Hello Community,

 

I was referencing this article → https://community.servicenow.com/community?id=community_question&sys_id=44738b25dbd8dbc01dcaf3231f961961&view_source=searchResult ← for guidance on using 'User Criteria' records with a custom table. 

I have a created a table with roles in it. This table will be referenced by a List Collector variable on a catalog item. I want to utilize User Criteria records on this custom table. If the user viewing the catalog item does not meet the User Criteria, the records from the custom table do not show as options in the List Collector variable. 

How can I accomplish this behavior? Again, referencing the article above, I can retrieve the User Criteria and determine if the user meets the criteria or not. But how do I show/hide records on that custom table(and in the List Collector variable) if the user does not meet the criteria?

1 ACCEPTED SOLUTION

Ken83
Mega Guru

I was able to find a solution to this. Utilizing the code outline in the article above, I'm able to retrieve a Java ArrayList object that contains sys_ids of the User Criteria records that the current user satisfies. Since it is not a native Javascript object, don't bother trying typical Array methods on it, won't behave as expected. Instead, I had to get the size of the ArrayList using the .size() method(equivalent of JavaScript .length() method) in a FOR loop. As I looped through that ArrayList object, I pushed each value out into a native JavaScript array using nativeJSArray.push(ArrayList.get(x)). Once I had the nativeJSArray populated, I just returned that to a before query Business Rule. Since it's a custom table, I added a reference field to reference the User Criteria table so that I could specify User Criteria for each row in the custom table. In the Business Rule, I just modified the query to check that the criteria returned, matched one of the criteria records identified on the records. Problem solved. Hopefully this is useful to someone looking to do the same. This will be something to re-visit after upgrades though to make sure ServiceNow hasn't deprecated the code outlined in that article.

View solution in original post

5 REPLIES 5

Mohiuddin2
Kilo Contributor

Hi Ken, do you mind sharing the business rule you ended up using? Did this end up replacing the ACL and script include all together? 

Thanks!