top of page

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

Dynamic and Advanced Reference Qualifiers in ServiceNow: A Complete Guide

Updated: Mar 29

In ServiceNow development, filtering reference fields dynamically based on other field values is a common requirement. Dynamic and advanced reference qualifiers help administrators and developers ensure users only see relevant options, enhancing both efficiency and user experience. In this article, we'll explain how to create dynamic reference qualifiers, particularly when the filtering depends on other field values like knowledge bases or categories.


Understanding Dynamic Reference Qualifiers

A dynamic reference qualifier adjusts available options in a reference field based on values entered in other form fields. The basic syntax involves JavaScript expressions that reference the current form context.

A standard example often used is:

javascript:"company=" + current.company

However, real-world scenarios typically require more complex logic than the simple examples provided in most ServiceNow documentation.


Practical Example: Filtering Groups by Knowledge Base

Consider the scenario where you have multiple knowledge bases, each with different support groups. When creating or editing a knowledge article, you want the 'Group' reference field to show different groups depending on the selected knowledge base.

Here's how you can implement this effectively:

Step-by-Step Guide:

1. Create a Script Include

Begin by creating a Script Include to encapsulate the logic:

var KBGroupUtils = Class.create();
KBGroupUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    initialize: function() {},
    filterGroupsByKB: function(kb) {
        var groups = [];
        var gr = new GlideRecord('sys_user_group');

        if (kb == 'KB1_SYS_ID') { 
		   // Replace with your KB sys_id
            gr.addEncodedQuery('type=TYPE_X^active=true');
        } else if (kb == 'KB2_SYS_ID') { 
		   // Replace with your second KB sys_id
            gr.addEncodedQuery('type=TYPE_Y^active=true');
        }
        gr.query();
        while (gr.next()) {
            groups.push(gr.sys_id.toString());
        }
        return 'sys_idIN' + groups.join(',');
    },
    type: 'KBGroupUtils'
};

In this script:

  • Replace 'KB1_SYS_ID' and 'KB2_SYS_ID' with actual sys_ids of your knowledge bases.

  • Adjust 'TYPE_X' and 'TYPE_Y' with the appropriate group types.


2. Update Your Reference Qualifier

Next, set the advanced reference qualifier of your reference field to call this Script Include:

javascript:new KBGroupUtils().filterGroupsByKB(current.kb_knowledge_base);

This dynamically applies the filtering based on the selected knowledge base.


Common Issues and Troubleshooting Tips

  • If your reference qualifier returns no results or all groups, first verify your encoded queries.

  • Using gs.info() within your script include can help debug by checking if the correct sys_id values are being passed and evaluated.


Alternative Approaches

While the Script Include method is highly recommended due to its maintainability and clarity, you can also directly implement advanced qualifiers using inline JavaScript expressions. However, this is generally less flexible for complex logic.

For example:

javascript: current.kb_knowledge_base=='KB1_SYS_ID'?'type=TYPE_X^active=true':'type=TYPE_Y^active=true'

Conclusion

Dynamic and advanced reference qualifiers significantly enhance the usability of ServiceNow forms by filtering reference field options based on contextual form data. Utilizing Script Includes for dynamic reference qualifiers is a best practice, especially in complex scenarios, as it centralizes logic and makes future updates easier.

To implement this effectively:

  • Define clear conditions for each scenario.

  • Use Script Includes to encapsulate complex logic.

  • Test thoroughly to ensure accuracy.

By following this structured approach, ServiceNow administrators and developers can ensure users have an intuitive and streamlined experience while maintaining clarity and control over backend logic.

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page