Advance view rules script for knowledge
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2025 08:52 AM
I'm working on a View Rule in ServiceNow where I need to display the "People_Zone_View" specifically when the knowledge base is "IT", and fall back to the default view for all other cases. I tried using dot-walking with current.kb_knowledge_base.name but it doesn't seem to be working as expected. Could you help me understand the correct approach for referencing the knowledge base name in a View Rule, or suggest a better way to implement this logic?
Here is the code:
Can anyone help me to solve?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2025 09:20 AM
view rule runs before the list/form is loaded and hence it doesn't have access to current object
For your requirement you will have to create multiple view rules based on unique conditions.
Also check this link which talks about the workaround
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2025 09:23 AM
I tried with this one now and still not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2025 10:16 PM
you didn't get the correct script from that link
Try this and enhance and debug
(function overrideView(view, is_list) {
// Use GlideRecord to get the knowledge base sys_id
var url = gs.action.getGlideURI().getMap();
var sysId = url.get('sys_id');
var kbGR = new GlideRecord('kb_knowledge_base');
if (kbGR.kb_knowledge_base == "a7e8a78bff0221009b20ffffffffff17") {
answer = "People_Zone_View";
}
})(view, is_list);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2025 02:43 AM
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader