How to restrict a custom created view to only system admins and members of a single assignment group

Arka Banerjee
Kilo Guru

Hi All,

 

I have created a custom view for a custom module list layout. I want to restrict that view to only be visible for admins and members of a particular assignment group. Also I would like to make that view as default view for members of that particular assignment group. Could you please help me achive this. Thanks!

 

@Ankur Bawiskar 

11 REPLIES 11

Shivalika
Mega Sage

Hello @Arka Banerjee 

 

You need to create a view rule for this view and add below 👇 condition - 

 

var user = gs.getUser();

var isAdmin = user.hasRole('admin');

var groupId = 'your_assignment_group_sys_id'; // Replace with your group Sys ID

var isInGroup = gs.getUser().isMemberOf(groupId);

 

// Return

 

To make it default view for users, you need to modify the sysparm_view user preference for them. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Chaitanya ILCR
Kilo Patron

Hi @Arka Banerjee ,

check the hidden check box in the view which hides it for non admin users

 

ChaitanyaILCR_0-1743527542147.png

2. Also I would like to make that view as default view for members of that particular assignment group

you can create a view rule for this

ChaitanyaILCR_1-1743527674471.png

 

by this users of that particular group will land in the view you have created and only admin users can see that view

no other user can see the view in the views

 

Note: user can still be able to open the records in that view by setting sysparm_view in the url but they cannot see the view in form context menu->views 

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

 

 

 

Hi @Chaitanya ILCR @Ankur Bawiskar PFAA screenshot of the view selection menu from the list context menu in the custom module.

That view should be available for selection along with the other 2 views only for admins as well as the members of that particular assignment group, so that both admins as well as members of that assignment group is able to toggle through these views(not just for admins but for the assignment group members as well). Additionally, whenever any user from that assignment group is opening this custom module list from the app navigation, the default view which should be appearing to them should be the 'Mass Operations' view.

 

From your above script, if I am impersonating any of the members of the assignment group and selecting 'Default view' from the view selection, its redirecting to 'Mass Operations' when it should redirect to default view. Can you kindly help with the above configurations.

 

ArkaBanerjee_1-1743591121548.png

 

Hi @Arka Banerjee ,

in that case you can add group value to the view and remove(deactivate) that view rule if have configured any

this way the users in the specified can see the view and toggle between the views 

others who are not a part of the group won't be able to see that view

ChaitanyaILCR_0-1743591884887.png

in the custom module you've created just add URL parameter sysparm_view=your_view_value to open the record that particular view 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya