How to restrict a form view based on the user group.

somasekharK
Tera Contributor

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.

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@somasekharK 

please share your view rule; it should be an easy one

if(gs.getUser().isMemberOf('Group ABC'))

answer = 'yourViewName';

else

answer = ''; // default view

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

HI When I used the above script, below are the outcomes.

-All users can able to open the user form with the new view.

-But still all ITIL users have access to this new view.

-Before implementing new view rule all ITIL users can't able to open the 'Default view' (only admins have this view access.)

- Now all ITIL users can able to access the default view. This is not a good outcome.

 

Below script I used'

if (gs.getUser().isMemberOf("ABC group")) {      

answer = "new_view";    

} else {
        answer = '';
    }

HI @Ankur Bawiskar ,

After implementing the above script in the view rule below are the outcomes.

- Still all ITIL users, who are not in that group can able to access the new view.

- And before implementing this view rule, ITIL users can't able to open the default view in the user form.

-Now all the ITIL users can able to open the default view in the user form, which is like a security breach.

if (gs.getUser().isMemberOf("ABC group")) {      

answer = "new_view";    

} else {
        answer = '';
    }

@somasekharK 

did you check the view rule is getting executed and view name is correct?

Did you add log statements and check?

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