- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 02:40 AM
Hi everyone,
I am currently working on a requirement where I need to evaluate User Criteria for a Knowledge Base at the Service Portal widget level.
Here’s what I’m trying to achieve:
We have user criteria set up for different Knowledge Bases.
I want to check if the logged-in user has access to a specific KB article or Knowledge Base based on the configured user criteria.
This check needs to happen inside a Service Portal widget (server-side or client-controller if needed).
What I’m looking for:
Best practice to evaluate user criteria via UserCriteria API (or any recommended approach).
What methods or APIs should I be using — e.g.,
UserCriteriaLoader() ?
UserCriteriaEvaluator() ?
Any specific helper like sn_uc.UserCriteriaLoader.getAllUserCriteria()?
How to invoke it correctly in a widget context (server script or client call to Script Include?)
Example or snippet to check if current user has access to a KB article or base using user criteria
What I’ve tried so far:
I’ve looked into sn_uc.UserCriteriaLoader, but I’m not sure if it’s the right fit here.
Also wondering if I need a Script Include or if there's a simple method to evaluate access inline.
Would really appreciate any insights, examples, or pointers from anyone who has implemented something similar!
Thanks in advance 😊
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 05:41 AM
Hi @ujjwala_678 ,
add your user crietria sysid in the array in the 2nd line (I have added a dummy one for reference) just replace it your user criteria sysid
replace the user_id with sysid of the user in the last line
try this
make adjustments if required
function checkCondition(user_id) {
var userCriterias = ['6b6df061ff2121009b20ffffffffff44']; //replace the array with your user criteria sysids
var meetsCriteria = sn_uc.UserCriteriaLoader.userMatches(gs.getUserID(), userCriterias);
var userHasRole = new GlideRecord('sys_user_has_role');
userHasRole.addQuery('user', user_id);
userHasRole.addQuery('role.name', 'admin');
userHasRole.query();
if (meetsCriteria && userHasRole.hasNext()) {
gs.info("user found");
return true;
}
return false;
}
answer = checkCondition(user_id); //replace user id with sys id of the user
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 02:45 AM
Did you check on the User Criteria Diagnostics that is OOB available?
Why do you need to check this from the portal? What is your business case for that?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 03:23 AM
Hello Mark,
Thank you for your inputs on this. I need to restrict portal widget access based on user's department hence trying to configure a user criteria which I can apply at the widget level.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 03:35 AM
Why not create a custom role, add that to a 'department group' where you automatically add/remove users based on the department and add that role to the widget.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 02:46 AM
Hi @ujjwala_678 ,
refer this
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya