How to Create and Run a view rule on a Custom View Name (List)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2024 09:54 PM
I want to run my view rule script on my custom list view named: Row 21 Affected User. But the view rule script only runs on the list default view.
What I'm trying to do is when there is at least one affected user field (custom field) that is not empty then the user can view the custom list view, otherwise it will redirect them back to the default list view.
I set the view variable in the script to "row_21_affected_user" and "row21AffectedUser". The script still runs on "Default view" and not on "Row 21 Affected User".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2024 08:34 PM
Yes, correct. When viewing the default view and affected user field count is greater than 1 it will change to 'Row 21 Affected User' view. Else if the affected user field is not populated (count is 0) then I wont be able to view the 'Row 21 Affected User' view and it will change to the default view.
As for the view name of the view it's actually 'row_21_affected_user'. I already tried it but the script still runs only on default view. I think it would be better if the view rule is runned only on the Row 21 Affected User view so that when I view it when count is 0 it will change to default view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2024 09:20 PM
Let's try removing all the script except the view name, something like:
(function overrideView(view, is_list) {
if (is_list) {
answer = "row_21_affected_user";
}
})(view, is_list);
If this works, something is wrong with your GlideQuery.
If it doesn't, either your view name is incorrect or something else is overriding it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2024 09:28 PM - edited 04-14-2024 09:30 PM
It works and runs, when I'm pressing the default view it changes or redirects me to the Row 21 Affected User view. But when I'm pressing other views the script does not run.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 01:17 PM
Right, I can see the same behaviour in my PDI as well.
Apparently there is a system property that needs to be set to false - glide.ui.remember_view
Refer to the following thread for details - https://www.servicenow.com/community/developer-forum/view-rule-script-is-working-only-on-quot-defaul...