Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Catalog Item Variable Depedency Issue (Fields Disabled/Visible Inconsistently)

anushinde05
Tera Contributor

Hi All,

 

I am working on a catalog item in ServiceNow and facing an issue with variable behavior.

In my catalog item:

  • I have a variable "Request Type" with 4 choices.
  • Based on the selected Request Type, another variable "Request Reason" is shown.
  • The "Request Reason" field contains 8 choices.
  • Further, based on the selected Request Reason, some related fields get populated and displayed.

Issue:

  • When I change the Request Type, some dependent fields:
    • Become disabled, or
    • Sometimes remain visible, and
    • Sometimes behave inconsistently (enabled/disabled/visible).

What I Tried:

  • Verified UI Policies and Client Scripts
  • Checked variable dependencies

Question:

  • Why are the dependent fields behaving inconsistently (visible vs disabled)?
  • Is there any best practice to manage such multi-level dependencies?
4 REPLIES 4

vaishali231
Tera Guru

hey @anushinde05 

This behavior typically happens due to overlapping control on the same variables, especially when both UI Policies and Client Scripts are involved.

 

 Root Cause

In multi-level dependencies like:

Request Type - Request Reason - Dependent Fields

the issue is usually:

  1. Child variables are not reset when the parent changes
  2. Previous UI Policy states remain applied
  3. Multiple sources (UI Policy + Client Script) are trying to control the same field

This results in:

  • Fields staying visible when they should hide
  • Fields becoming read-only unexpectedly
  • Inconsistent behavior on change

 

 Approach

1 . Reset child variables on parent change

Create an onChange Client Script on Request Type:

function onChange(control, oldValue, newValue, isLoading) {

   if (isLoading) return;
   // Reset child variable
   g_form.setValue('request_reason', '');
   // Reset all dependent fields
   var fields = ['field_1', 'field_2'];
   fields.forEach(function(field) {
       g_form.setDisplay(field, false);
       g_form.setReadOnly(field, false);
       g_form.clearValue(field);
   });

}

 

2 Use clear responsibility

  • UI Policies - control Visible / Mandatory
  • Client Scripts - handle reset and flow control

Avoid both controlling the same property.

3 . Ensure “Reverse if false” is checked

Without this, fields retain their previous state when conditions change.

4. Keep dependency flow strict

Request Type - controls Request Reason

Request Reason - controls dependent fields

Avoid controlling deep-level fields directly from Request Type.

 

*************************************************************************************************************************************

If this response helps, please mark it as Accept as Solution and Helpful.

Doing so helps others in the community and encourages me to keep contributing.

Regards

Vaishali Singh





 



Hi @vaishali231,

 

Thanks for your response.

 

In our case, we have created UI Policies based on Request Reason in ServiceNow.

 

If Request Reason = Network, network-related variables are displayed

If Request Reason = Software, software-related variables are displayed

 

However, the issue is:

 

When we switch from Network → Software → back to Network,

some of the network-related variables are not showing again

 

It seems like previous UI Policy states are not getting reset properly.

 

Could you please suggest how to handle this scenario so that fields always display correctly when switching values?

 

Thanks!

Ankur Bawiskar
Tera Patron

@anushinde05 

since you have multiple levels of dependencies you need to make sure the relevant UI policy on Request Reason triggers well and does it's job based on change of Request Type

what debugging did you do?

share your findings.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

 

Thanks for your response.

 

In our case, we have created UI Policies based on Request Reason in ServiceNow.

 

  • If Request Reason = Network, network-related variables are displayed
  • If Request Reason = Software, software-related variables are displayed

 

However, the issue is:

 

When we switch from Network → Software → back to Network,

 some of the network-related variables are not showing again

 

It seems like previous UI Policy states are not getting reset properly.

 

Could you please suggest how to handle this scenario so that fields always display correctly when switching values?

 

Thanks!