Change form view using switchview if user has a specific role using client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2022 03:37 AM
Please help I'm trying to change the view of the form using switchview in client script if user has a role please see below..
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2022 03:58 AM
Hi,
If your requirement is to set default view for a specific role then I suggest you to create View Rule. Follow the below steps
1) Navigate to System UI > View Rules
2) Click New button
3) Set following values
Name : Some meaningful name
Table : <your table name>
Advanced : Checked
Script: (Update the view name and role name with actual values
(function overrideView(view, is_list) {
if (gs.hasRole("<type the role name>")) {
answer = "<type the view name>"; // set the new view to answer
return;
}
answer = view;
})(view, is_list);
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 04:31 AM - edited 01-16-2024 04:31 AM
Hi Palani,
Mentioned view going to applicable for admin also.
When I used gs.hasRoleExactly the view is not applying at all.
When I used gs.hasRole view going to be applicable for intended user as well as admin.
Please help me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 02:12 AM - edited 08-01-2024 02:14 AM
Hello,
Please check this script for reference.
I have used it in a UI Policy that has no conditions and it is working on the incidents table.
Generally what it does is if the view is not default and if the user is not admin, it sets is as the default and informs the user.
View Rules do not work in order to restrict users not to use other views.
View Rules are triggered only when you select the default view in the view changer.
Also if you do not use the advanced option in a View Rule it hides the Vie Changer option and uses the view that is set in the view rule but it does not do the same when you use the advanced condition.
Im using a UI Policy since I determined that the work faster than client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 02:31 AM
Great solution, had tried to force users to default view via view rules. Never worked.
Thanks a lot for this!