We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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. 

6 REPLIES 6

Sachin_Nasa
Tera Guru

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


Thanks & Regards,
Sachin Narayanasamy

NO not working

 

Hi,i need for below requirment

Catalog variable field name : u_environment

select box: development,test.production

variable set Field name : server_list
lookup list: cmdb_rel_ci 
here i need to filter child list

and based on environment value i need to filter child server with environment filter 
if environment is development the this should only visible development servers in child list .
please some one suggest how to get this filter from Core catalog item variable to variable set.
thanks

Brad Bowman
Kilo Patron

For a 100% human (and correct) response, if you are using the out of box field named 'environment' extended from the cmdb_ci table to track which servers are used in which environment, the choice values are 'Development', 'Test', and 'Production'.  If these are the values in your instance your Catalog Item variable choice values should be exactly the same (you can display Dev, Test, Prod if you really want to as long as the value of the choices exactly match).

 

Then, all you need to do is set the reference qualifier on the reference variable to something like this:

BradBowman_0-1770229087191.png

where 'v_environment' is the name of the select box variable.

 

If the reference variable is in a multi-row variable set, and the select box variable is not, that's a different issue, but since you didn't specify I'm assuming for now that it is in a single row variable set.