User criteria to exclude admins
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 07:25 PM
Hi,
I have a question regarding user criteria in catalog item. We want to display catalog item for vip users only and exclude admins.
Ex:
ABC is admin
XYZ is vip
123 is admin and vip
So display catalog item for XYZ and 123 not ABC
Thanks
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 07:39 PM
Hi,
In use criteria try this scripts in advanced option.
var userRecord = new GlideRecord("sys_user");
userRecord.addQuery("sys_id", gs.getUserID());
userRecord.query();
if (userRecord.next()) {
if (userRecord.vip=='true'){
answer = true;
}else{
answer = false;
}
}
Feel free to mark helpful & correct!
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 08:27 PM
Hi
I tried above script it is available for admins as well even though user is not vip.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 10:30 PM
Hi
Admins will always see the Catalog Items (Record Producer and Order Guides) despite the User Criteria denying the access.
Reason: System Property "glide.sc.entitlement.override" allows Admins to see all the Catalog Items
To implement your requirement, you need to remove the role from the property or change it to security_admin so that admins are not allowed unless access is provided by User Criteria.
In User Criteria, you need to add logic as provided below:
//Never user gs.getUser() or gs.getUserID() in User Criteria
//Instead use pre-defined variable "user_id"
answer = false; //Deny access initially
var getUser = new GlideRecord("sys_user");
if(getUser.get(user_id)) {
if(getUser.getValue('vip') == 'true')
answer = true;
}
Remark: Never use gs.getUser() or gs.getUserID() in User Criterias
Please try and check if this works for you.
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik