User criteria to exclude admins

chandukollapart
Tera Contributor

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

3 REPLIES 3

Sagar Pagar
Tera Patron

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

The world works with ServiceNow

Hi @Sagar Pagar 

 

I tried above script it is available for admins as well even though user is not vip.

 

Thanks

Kartik Sethi
Tera Guru
Tera Guru

Hi @chandukollaparthi 

 

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