Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Advance view rules script for knowledge

Apaul
Tera Contributor

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?

TribalChief_0-1748533682195.png


Here is the code:

(function overrideView(view, is_list) {
    var answer = view; // Default to the current view

    // Access the knowledge base record
    var kb = new GlideRecord('kb_knowledge_base');
    kb.addQuery('sys_id', current.kb_knowledge_base);
    kb.query();

    if (kb.next()) {
        // Check if the knowledge base name is "IT"
        if (kb.name == "IT") {
            answer = "People_zone_view";
        }
    }

    return answer;

})(view, is_list);

Can anyone help me to solve?
5 REPLIES 5

I didn't use the script later as view rule condition was enough to do it bro.