logo

NJP

How to Change a Reference Qualifier Inside a Variable Set

New article articles in ServiceNow Community · Sep 03, 2026 · article

The Issue

When a reference variable is part of a single-row variable set, you may need to change the reference qualifier for one or more catalog items while not disturbing the list of records shown on all of the other catalog items where the variable set is used.

 

Workarounds

  1. Not use the variable set - re-create all the variables for the exception catalog item(s)
  2. Create one variable with the new reference qualifier in the catalog item or within the variable set, then hide the original variable on the new catalog item.

Both of these require creating one or more extra variables, causing issues with downstream usage and reporting across catalog items, or copying the variable value and keeping it in sync.

 

A Solution

A simple approach is to always set the reference qualifier from a script include.  The SI returns the results based on the catalog item, using system properties to make all of this scalable and reusable.

 

A Detailed Example

We have a reference variable named  v_configuration_item  that is a reference to the  cmdb_ci  table in a single-row variable set that has been included in a number of catalog items. The simple reference qualifier for this variable, as seen when switching it to advanced, is:

sys_class_name=cmdb_ci_ip_router^ORsys_class_name=cmdb_ci_ip_switch

Example 1.1: This qualifier will only show routers and switches in the list of CI records.

 

In developing a new catalog item, we want to use this variable set, but for this CI variable we also want to show  VPN  (cmdb_ci_vpn) records. To meet this requirement, complete these steps:

 

  1. Change the advanced  Reference qualifier  on the variable to something like:

    javascript:new refQualUtils().getRefQual(current.cat_item,'sr.ref.vs.ci.cat_items','sr.ref_qual.ci.orig','sr.ref_qual.ci.new');

Example 1.2: Use any compliant names for a script include, function, and 3 system property names.

 

This reference qualifier will pass the catalog item sys_id and 3 system property names to a script include.  Creating 3 system properties will allow us to re-use the script include function for other similar use cases, if the original and new reference qualifiers are simple enough to be stated in an encoded query string as in this example.  For more advanced reference qualifiers, create only the first, or no, system properties, then use similar logic in the script include to ultimately return one of two complete reference qualifiers based on the catalog item sys_id. 

 

  1. Create a system property with the  Value  = the sys_id(s) of the catalog item(s) that will use the new reference qualifier.  Separate  sys_ids  with a comma, a space, or your favorite emoticon {;-{) 

BradBowman_0-1788439487448.png

 

  1. Create a system property with the  Value  = the original reference qualifier.

BradBowman_1-1788439487466.png

 

  1. Create a system property with the  Value  = the new reference qualifier.

BradBowman_2-1788439487465.png

 

  1. Create a script include which will return the complete reference qualifier from one of the system properties, determined by the catalog item being included, or not, in the exception list system property:

    var refQualUtils = Class.create();
    refQualUtils.prototype = {

        initialize: function() {
        },    

        getRefQual: function(catItemID, propNameCatItem, propNameRQOrig, propNameRQNew) {
            var answer = '';
            if (gs.getProperty(propNameCatItem).indexOf(catItemID) != -1) { //catalog item found in the system property
                answer = gs.getProperty(propNameRQNew); //use the new reference qualifier
            } else {
                answer = gs.getProperty(propNameRQOrig); //use the original reference qualifier
            }
            return answer;
        },

        type: 'refQualUtils'
    };

Now you can re-use a variable set, but change a reference qualifier for one or more catalog items, without adversely affecting the other catalog items using the variable set!

View original source

https://www.servicenow.com/community/service-catalog-articles/how-to-change-a-reference-qualifier-inside-a-variable-set/ta-p/3594579