How to restrict a custom created view to only system admins and members of a single assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 09:18 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 05:15 AM - edited 04-02-2025 05:18 AM
That view should open as a default view only for members of that assignment group when they open the module. For others who are not part of that group, they should still be able to open that module, just that the view should not be visible for them. How can I achieve this? As I believe as per the solution you had suggested, it will try to open the 'Mass Operations' view as default for every user, so users not part of that group will be directed to that view which is not what we want. Could you please help..
Also where exactly do I need tp set URL parameter. PFB screenshots
Also, if I set the group at the view level, it will restrict me from adding more groups if it would be required in the future for visibility of that view. Could you please suggest something dynamic in this case so that I can add more groups in the future
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 09:35 AM
Hi @Ankur Bawiskar Could you please help me with the above query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 09:46 AM
I am logging off now, will check and try to respond tomorrow
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 11:35 AM
Hi @Arka Banerjee ,
How about a custom role?
add that role to the view (only users with that particular role can see the view)
this is more scalable
I have tried script include to set the view through the url using sysparm_view but it didn't work
seems like this can't be achieved with compromises
here the compromise being the group the you are pointing to you can ask them to change their view manually in the list of the table in any module of the table which stores it in the user preferences. unless they change their view it will stay as their selection.
or you can run a script and create user preference records of those users
this is a ontime activity
var usr = ['itil','abel.tuter','admin'] //user_name of the users
usr.forEach(function(i){
gs.getUser().getUserByID(i).savePreference('incident_list.view','ess');
});
here i have taken incident table as an example replace incident with your table and "ess" with your view name
('yourtable_list.view', 'yourviewname')
2. found an alternative and which suits your requirement
the custom role part for the view stays as is as you wanted to this to be scalable
otherwise go with the group approach
create an UI page
html
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate jelly="true">
var encQuery = 'active=true^assignment_group=' <!-- update your modules encoded query here-->
var group = 'Help Desk' <!--sysid or name of the group better store sysid-->
var tableName = 'incident' <!--replace with your table name-->
var viewName = 'test_view' <!-- replace with your view name-->
var url = tableName+'_list.do?sysparm_query='+ encQuery;
if (gs.getUser().isMemberOf(group) || gs.hasRole('admin')){
gs.getUser().savePreference(tableName+'_list.view',viewName)
}
var view = gs.getPreference(tableName+'_list.view')
</g:evaluate>
</j:jelly>
ui page client script
window.location= '${url}'+'&sysparm_view='+'${view}';
I have added HTML comments to the above UI page HTML update them as per your table and requirement
in your module
change it to URL type and in the arguments use the UI page name.do
here I have given testing feel free to change it
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 08:00 PM
check approach shared by @Chaitanya ILCR and it should work for you.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader