How to fix View by user role

Inoue2
Tera Contributor

Hi, experts.

I would like to fix View by user role.

I have created one user and one role and assigned that role to that user.

I would like to do the following.

1. I would like to create a view that only that user can use.

2. If that user is in control, the view will appear on the screen.

3. However, if the controller is not that user, then the view cannot be used.

4. (if possible) It cannot be changed from its default view if that user is in control.

Please give me your hand.

I'm not good at English, If these sentences is hard to read for you, I'm apologize.

1 ACCEPTED SOLUTION

You can go to the UI views under the System UI look for your View in list, Open the record and you will be able to see. If no role is assigned then by default views are visible to Admin or Itil-user since they have access to create view and control them.

If you don't want admin to have access to the view you need to write another If statement and add the gs.hasRole("admin") and answer=false. Only this way you can revoke the admin access to views. As being admin, all access is available to them.

 

View solution in original post

10 REPLIES 10

Anil Lande
Kilo Patron

Hi,

You can use view rule to control view based on logged In user.

Please check below link for similar solution:

https://community.servicenow.com/community?id=community_question&sys_id=6596a95fdbdc8510457ae6be1396...

 

Thanks,
Anil Lande

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Ashir Waheed
Kilo Sage
Kilo Sage

Hi Inoue,

1. Go to the View Rules module under the System UI application in Application Navigator.

2. Create a New view rule, Choose the desired Name and the Table that has the view you created.

3. After this checked the Advanced option you will see on the form.

4. Script will be available, Here you will define the role that you have created in script 
    gs.hasRole("your role").

5. In answer variable you will write the view name that you have created  answer="your view".
    For those who should not access the view write answer=" " or answer=null.

6. View the image below to understand the script.

find_real_file.png

7. In case you don't know the exact view name, you can navigate to Views under System UI application.




Regards,

Ashir Waheed

Thank you for reply.

How do I check if user with specific role is allowed to use a view?

If I impersonate someone with the admin or itil role, I can still use that view.

I have created the following view rule.

 

find_real_file.png

You can go to the UI views under the System UI look for your View in list, Open the record and you will be able to see. If no role is assigned then by default views are visible to Admin or Itil-user since they have access to create view and control them.

If you don't want admin to have access to the view you need to write another If statement and add the gs.hasRole("admin") and answer=false. Only this way you can revoke the admin access to views. As being admin, all access is available to them.