How to restrict catalog form to only particular users?

Venkat141
Tera Contributor

How to restrict catalog form to only particular users?

 

@Ankur Bawiskar 

@Saurav 

@shloke04 

@Anil Lande 

@Maik Skoddow 

@Jaspal Singh 

@Sandeep Dutta 

@Chandra Sekhar Maganty 

@Musab Rasheed

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Pavan Ramireddy 

use advanced script in user criteria and then add this user criteria in Available for related list of that item

As recommended practice please use user_id to get logged in user sys_id

var rec = new GlideRecord('sys_user');
rec.get(user_id);

if (rec.u_division == 'OIT Information Technology')
	answer = true;
else
	answer = false;

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

13 REPLIES 13

Sagar Agarwal
Mega Guru

Hi @Pavan Ramireddy 

 

You can create user criteria with the below configuration and add to the "Available for" related list if you want only these users to be able to view this catalog item and under "Not Available for" if you want this catalog item to be not available for these users.

 

Search for user criteria in application filter to create new criteria OR click on the NEW button under Available For related list on catalog item form

User criteria details:

Name: User division is OIT Information Technology

Advance: Checked/true

script:

/**
 * Return true is user division is OIT Information Technology
 * else return false
 */
var gr = new GlideRecord("sys_user");
gr.get(gs.getUserID().toString());
if (gr && gr.division.toString() == "OIT Information Technology") {
	return true; // User Division is "OIT Information Technology"
}
return false;

 

 

If my answer helped you in any way, please then mark it as helpful.

Kind regards,

Sagar

Can you write a script that looks for a title of the sys user instead of department?  Looking to add to the "Available For" on a catalog item, that is restricted to access only if they are a Manager.

 

Thanks!

Hi @terrieb try below code

/**
 * Return true if user title is "Manager"
 * else return false
 */
var gr = new GlideRecord('sys_user');
if (gr.get(gs.getUserID())) {
    if (gr.title.toString() == "Manager") {
        return true; // User title is "Manager"
    }
}
return false;

terrieb
Tera Guru

I got it to work but will it work if I change the "is" to "contains" instead?  We have several "manager" levels, not just "manager" like Senior Manager, etc...

 

Thanks!