- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2019 02:55 PM
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?
Solved! Go to Solution.
- Labels:
-
Best Practices
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2019 11:23 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2019 03:01 PM
Ken, this sounds complicated to use user criteria. Do you expect the criteria to change often? ACLs maybe an easier way to manage this in combination with a reference qualifier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2019 05:37 AM
Michael, thank you for that suggestion. Yes, I expect these criteria to change often or to be added often. We will have several groups/departments with different criteria added at different times. I initially started down this road with ACLs but thought the User Criteria would be easier.
Taking the path of using ACLs, I'll probably have to extend that to a script include so that I can make it data-driven to accommodate all the changes/additions of user criteria. Basically, the idea i had was to use the script field of the ACL to utilize the script include. The script include will reference the User Criteria records so that I can determine if the user matches the associated criteria record.
The issue I ran into with this approach is that I can't seem to get the Read ACL to restrict the record in the custom table list view if the ACL script returns false. Sounds simple, but i'm not sure what i missed. My assumption is that if the ACL is restricting 'Read' access to that row in the table, then from a catalog item(list collector variable), that row won't be visible which is exactly what I want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2019 09:17 AM
This is the script include I am using in the ACL script...
This is the ACL script...
The User Criteria record is checking for a specific location. The user I am testing with does not meet the criteria, but can still see the record in the list view.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2019 11:23 AM
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.