Hide a field in a catalog item view based on requestor's user role

GamNOW
Tera Contributor

Hello Everyone,

 

How can you make a certain field invisible and not mandatory?

 

There is a UI policy set to where if urgent request is 'Yes'

Need by Date and Approving Deputy Director is mandatory and visible.

 

But in a catalog item view in the Service Portal, I want to make 'Approving Deputy Director' invisible and not mandatory if the person submitting the form has 'deputy_director' role.  How can I achieve this?  (I am using Yokohama)

GamNOW_0-1760134289242.png

 

10 REPLIES 10

SanjivMeher
Mega Patron

You need a client script in this case. You can check if the current user has this role using below line and then make field visible or mandatory

g_user.hasRole('deputy_director');

 

Rafael Batistot
Mega Patron

Hi @GamNOW 


use g_user.hasRole(): This function is available in client-side scripts (including those in UI Policies) and is the standard way to check for a user's role in the browser/Service Portal.

 

https://youtu.be/_FB5FBdYcmY

hide fields in servicenow | How to hide the fields on form | How to Hide a Field using a UI POlicy This video provides a practical "servicenow tutorial" on using "servicenow ui policy" to manage form behavior within catalog items. You'll learn essential "servicenow scripting" techniques to make ...

Raghav Sharma24
Giga Patron

There is a possibility to check loggedin users roles in client script:

 

g_user.hasRole(“deputy_director”)

{
// write your logic for madatory and visible,

}


Please mark the answer correct/helpful accordingly.

@GamNOW Did this answer?