How to restrict form views based on role?

Community Alums
Not applicable

Hi,

Consider we have 3 views as below

view 1

view 2 

view 3

Above 3 views are visible to admin and itil users. But I want to restrict in such a way that, itil users should see only view 1 and view 2, not view 3. 

Can anyone suggest how we can achieve this. Thank you!

NOTE: I tried adding roles to System UI -> Views -> on Role field but it didn't work. 

3 REPLIES 3

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

You can create View Rule

Control when the system displays a view | ServiceNow Docs

-Anurag

-Anurag

Community Alums
Not applicable

Hello Anurag,

I tried that with below script 

i,e 

if(gs.hasRole('itil'))){

answer = 'view 1' }

But Whenever I do impersonate to ITIL user, form is forcing me to stay in view 1. Its not allowing me to change the view also. 

 

Could you please suggest me sample script to achieve this. Thank you!

Haven't tried this myself but how about something like this?

var view = g_form.getViewName();
if (gs.hasRole('itil') && view == 'view 3') {
  //Only revert to view 1 as a default if view 3 is selected
  //otherwise allow user to select view
  answer = 'view 1';
}

 


The opinions expressed here are the opinions of the author, and are not endorsed by ServiceNow or any other employer, company, or entity.