How to restrict view based on role?

sowmya28
Tera Contributor

I have one view called "Demo_View". I need to restrict this view only to users with Role "Viewers".

I tried adding role to view and adding view rule but it didn't work.

Please help me how can I achieve it. Thanks in advance.

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

so what script did you write?

share that

Regards
Ankur

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

(function overrideView(view, is_list) {

// Add your code here

var isSysAdmin = gs.hasRole("Admin");
var isViewer = gs.hasRole("Viewers");

if(isViewer && !isSysAdmin){
answer = "demo_view"; // set the new view to answer
} else{
answer = "default";
}

})(view, is_list);

Hi,

Don't test with admin role as admin will inherit all roles

with which role user you are testing?

are you sure name of view is correct? demo_view

regards
Ankur

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

yeah i tried without admin 1st. It didn't work so I have added now. View name is correct only

.