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

Hi @Chaitanya ILCR 

 

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

 

ArkaBanerjee_1-1743596091468.pngArkaBanerjee_2-1743596143839.png

 

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

 

Hi @Ankur Bawiskar Could you please help me with the above query

@Arka Banerjee 

I am logging off now, will check and try to respond tomorrow

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

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

 

reference :https://www.servicenow.com/community/developer-forum/dynamic-redirection-on-module-click-in-jakarta/...

 

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

ChaitanyaILCR_1-1743618650558.png

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

ChaitanyaILCR_2-1743618707783.png

 

 

 

 

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

Regards,
Chaitanya

Ankur Bawiskar
Tera Patron
Tera Patron

@Arka Banerjee 

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.

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