How to restrict the view based on role

JK9903
Mega Guru

Hello everyone,

I would like to restrict users from changing the view in the RITM and sc_task tables. Specifically, if a user has the "xyz" role, the view should always remain as "demo view," and they should not be able to switch to any other view.

 

I have already created a view rule for this requirement, but users are still able to change the view. Is there a way to enforce the view so that they are always restricted to "demo view"?

Thanks,
JK
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@JK9903 

see this KB which talks about this, it says don't use script to set view
Script doesn't set the view in the View Rule

also explore about navigation handler and see how it works

ServiceNow Hidden Gem #1: Navigation Handler  

Navigation handler 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron

@JK9903 

see this KB which talks about this, it says don't use script to set view
Script doesn't set the view in the View Rule

also explore about navigation handler and see how it works

ServiceNow Hidden Gem #1: Navigation Handler  

Navigation handler 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@JK9903 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Hi @Ankur Bawiskar,

 

Thanks for the article, I've used navigation handler and it worked as I expected. But still, it is not completely restricting the user from changing the view.

 

var gr = new GlideRecord('incident');
if (gr.get(g_uri.get('sys_id'))) {
if (gs.getUser().hasRole('itil'))
g_uri.set('sysparm_view', 'playbook_card');
}
answer = g_uri.toString('incident.do');

Thanks,
JK

@JK9903 

so are they able to switch?

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

@Ankur Bawiskar ,

Yes, initially it is setting the view as I specified in the navigation handler, but they can be able to change the view.

Thanks,
JK