How to Access Variable set based on Variable selection

rajibosss11
Tera Contributor

HI,

 

I have a doubt on this 

Catalog item variable name : Environment choices , prod,test,dev

variable set field : Server name : reference cmdb_aix_server 

 

When I select the Environment choice in the catalog variable, only the corresponding servers (Dev, Test, or Prod) should be available in the Server Name field. The reference list must be filtered based on the selected environment. 

1 REPLY 1

SachinNasa
Tera Contributor

Hi @rajibosss11 ,

To filter the Server Name reference variable based on the selected Environment (Dev/Test/Prod) in a catalog item or variable set, you should use an Advanced Reference Qualifier along with a Catalog Client Script.

 

Step-by-Step Configuration

1. Catalog Variable – Server Name

  • Type: Reference

  • Reference table: cmdb_aix_server

Navigate to:

  • Catalog Item / Variable Set → Variables

  • Open Server Name

  • Set Reference qualifier = Advanced

Script:

 

 
var env = current.variables.environment; if (env) { return 'u_environment=' + env; }

 

 

Update u_environment to the actual environment field name in your CMDB table if it differs.


2. Catalog Client Script (onChange)

This ensures the reference list refreshes when the environment changes.

Navigate to:

  • Service Catalog → Catalog Client Scripts → New

Configuration:

  • Applies to: Catalog Item (or Variable Set)

  • Type: onChange

  • Variable name: environment

Script:

 

 
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || !newValue) { return; } g_form.setValue('server_name', ''); g_form.refreshReference('server_name'); }
 

Result

  • Selecting Dev → only Dev servers are shown

  • Selecting Test → only Test servers are shown

  • Selecting Prod → only Prod servers are shown

The server list updates dynamically without page reload.

If you find this response helpful, please mark it as Helpful and accept it as the solution if it addresses your question—it would encourage me to contribute more to the ServiceNow Community.

 

Thanks & regards,
Sachin Narayanasamy