- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2020 10:48 PM
I have created a view and a role for custom requirements. Now I have to set that view based on the role. Whichever user has that role needs to be shown only the custom view and they should not be able to change it.
I have created a view rule with the below script but it's not working.
(function overrideView(view, is_list) {
if (gs.hasRole("myteam_it"))
{
answer = "myteam_it_view";
}
})(view, is_list);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2020 11:36 PM
This behavior is the OOTB one and it's NOT possible to override the user preference, this was a decision made by ServiceNow, please refer to the following official HI article which describe exactly your use case:
https://hi.service-now.com/kb_view.do?sysparm_article=KB0719228
If I have answered your question, please mark my response as correct and/or helpful.
Thank you very much
Cheers
Alberto

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2020 10:58 PM
Hello,
Please use the OOTB view rule,
you can set condition role and view there, if all these 3 evaluate to true, the view will get change.
Please keep posted if want more help.
Please Mark it helpful/correct if my answer helps in any way to resolve your query.
Reach out to me if any more help required.
Regards
Yash.K.Agrawal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2020 11:00 PM
Hi,
try with the following script, it should work:
(function overrideView(view, is_list) {
if (is_list){
if (gs.hasRole("myteam_it"))
{
answer = "myteam_it_view";
} else {
answer = null;
}
})(view, is_list);
If I have answered your question, please mark my response as correct and/or helpful.
Thank you very much
Cheers
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2020 11:29 PM
Tried your script although one brace was missing. It did not work, the user having the role is able to change the view. If the user is having that role, the view should not be changeable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2020 11:36 PM
This behavior is the OOTB one and it's NOT possible to override the user preference, this was a decision made by ServiceNow, please refer to the following official HI article which describe exactly your use case:
https://hi.service-now.com/kb_view.do?sysparm_article=KB0719228
If I have answered your question, please mark my response as correct and/or helpful.
Thank you very much
Cheers
Alberto