Andrew_TND
Mega Sage
Mega Sage

Bit of back story

I've been working on a project recently where I had to create a dependency between two fields... I scoured the community and the only solution was create convoluted client script, with script includes it was going to be a logistical nightmare.

Admittedly I didn't come up with the solution however, I wanted to share it with you to help others who maybe in a similar situation.

The solution is actually using a an advanced reference qualifier on the catalog variable you would like to be dependent.

Lets get started

As an example...

If you have a variable referenced field... Lets say based on the user table (sys_user) where you need to select a user but thousands to choose from. 

You also have a location field variable based on the Location table (cmn_location).

If you select a location it narrows down the search results of your user variable based on the location using the advanced reference qualifier on the user variable field as found below...

find_real_file.png

The solution
If you are are not a coding master you may find advanced reference qualifiers a bit scary so I've added a simple example script below which will help you with some instruction.

This looks at active users where their location matches the location referenced in your variables.

javascript: 'active=true^location='+current.variables.location

To explain,

The first part - 'active=true^location' is looking at the active status and the location in the field your setting the advanced reference qualifier.

The second part ='+current.variables.location is matching it to your other variable field mentioned on the form.

Hope this helps!

I have submitted an idea to make this similar to normal fields so would appreciate an up vote to be considered for future releases.... Catalog variable dependency

And please mark as helpful if you've found this useful.


Comments
DrewW
Mega Sage
Mega Sage

I believe you missed the step of adding a "Variable attribute" of

ref_qual_elements=<VAR NAME USED IN REFQUAL>

so in your case you need to add the below to the "Variable attribute" field of the dependent variable.

ref_qual_elements=location

 

Docs
https://docs.servicenow.com/bundle/orlando-it-service-management/page/product/service-catalog-management/reference/variable-attributes.html

 

Version history
Last update:
‎10-29-2021 03:17 AM
Updated by: