How to restrict a form view based on the user group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2024 05:50 AM
Hi,
I created a new view in the user table, now all the ITIL users can able to see the new view. But I want to give access to this view for few particular groups only, and other itil users who are not in the mentioned groups can't able to see/ open this new view.
I tried to create a view rule, but failed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2024 11:38 PM
I have checked the conditions with log messages, the view rule working fine and logs created properly.
And I updated the script to restrict default view to non admins. like below,
answer=view;
if (gs.getUser().isMemberOf("ABC group")) {
answer = "new_view";
} else if (gs.hasRole('admin') {
answer = 'view'; //For Native View
} else {
answer = 'esc_user';
}
Below are the outcomes,
-if the users in the new group open any user record by default the view is "new_view"
-if any ITIL user open any user record by default the view is 'esc_user', but ITIL users can able to change to other views as well as 'new_view'.
-My problem is I want to restrict ITIL users to change the view to 'New view'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2024 12:03 AM
Hi @somasekharK ,
Create a new role and add it to view record that you have created and Add the role to those groups which should see this view.
the users who doesn't have the role won't see the view in view dropdown from the header.
note: the users might still be able to open the records in that view by setting the sysparm_view in URL
If this helped please leave a like and mark this as correct.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2024 01:56 AM
yes, I would combine View rule with this if required
if you want to restrict users of the group to open the record in that view alone.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2024 01:26 AM
Hello @somasekharK
for your requirement, I would go with Ankurs approach as you can add groups you want and restrict the view to others
Please mark the answer as helpful and correct if helped.
Kind regards,
Ravi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2024 05:49 AM
Hi,
Finally I got the solution by using the client script,
- Main problem I am facing here by using view rule I can able to set the default view of the users under the required group to the required 'new_view'.
But still all ITIL users(who are not in the selected group) can able to change their view to the 'new_view'.
So form view rule this is not achievable, but by using the client script I achieved this using below script.
function onLoad() {
var urlref = top.location.href; //Get the URL
//Only run when user have itil and the view is 'new_view'
if ((g_user.hasRoleExactly('itil')) && (urlref.indexOf('new_view') != '-1') && !g_user.hasRole('admin')) {
var grmem = new GlideAjax('Ajax_name'); //theck the logged in user is part of the required group.
grmem.addParam('sysparm_name', 'checkGroup'); //Give true or false response
grmem.addParam('sysparm_user', g_user.userID);
grmem.getXML(resp);
function resp(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//If user not belongs to respective groups
if (answer == 'false') {
switchView('section', 'sys_user', 'esc_user'); }
}
}
}
--But when the form first load (for users not part of the required group)some times this script not executing properly, when I reload the user form again this script working properly.