We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

ui polices

vodnalar26
Tera Contributor

Title

UI Policies not working to show/hide fields based on Request Type in ServiceNow form

Description

Hi everyone,

I'm developing a custom Access Request form in ServiceNow where fields should be displayed based on the selected Request Type.

My requirement is:

  • Add Role → Show Select Role and Source User
  • Add Multiple Roles to User → Show Select Multiple Roles and Source User
  • Add Multiple Roles to Multiple Users → Show Select Multiple Roles and Select Multiple Users
  • Add Group → Show Select Group and Source User
  • Add Multiple Users to Single Group → Show Select Group and Select Multiple Users
  • Add Multiple Users to Multiple Groups → Show Select Multiple Groups and Select Multiple Users
  • Copy Access → Show Source User and Target User

Initially, all these fields should be hidden.

I created separate UI Policies for each Request Type condition to show/hide the required fields, but the UI Policies are not working as expected. The fields remain visible (or do not change) when I select a different Request Type.

I also tried implementing the same logic using an onChange Client Script, and although the script executes and newValue is correct, the fields still do not show/hide.

Environment

  • Custom table
  • Request Type is a Choice field with values 0–6
  • Using the Next Experience form (see attached screenshots)

My questions

  1. Do UI Policies support dynamic field visibility in the Next Experience form?
  2. Is there any limitation with g_form.setDisplay() or UI Policies in this UI?
  3. Should I use Client Scripts, UI Policies, Workspace Client Scripts, or another approach to implement this requirement?
  4. Has anyone implemented similar dynamic field visibility in the Next Experience form?

I've attached screenshots of my form and the expected behavior.

Any suggestions would be greatly appreciated. Thanks!

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@vodnalar26 

share script here instead of script screenshot

what debugging did you do?

Did the onChange run?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Tanushree Maiti
Tera Patron

Hi @vodnalar26 

 

You will need to create 7 distinct policies (one for each Request Type rule)

  1. Navigate to Service Catalog > Catalog UI Policies > click New.
  2. Ensure Reverse if false is checked.
  3. Fill out the specific mappings via the Catalog UI Policy Actions related list:

UI Policy Condition (request_type is...)

 

Actions: Set Visible to True

Actions: Set Visible to False (Handled by Reverse if False)

Add Role

select_role, source_user

All other variables

Add Multiple Roles to User

select_multiple_roles, source_user

All other variables

Add Multiple Roles to Multiple Users

select_multiple_roles, select_multiple_users

All other variables

Add Group

select_group, source_user

All other variables

Add Multiple Users to Single Group

select_group, select_multiple_users

All other variables

Add Multiple Users to Multiple Groups

select_multiple_groups, select_multiple_users

All other variables

Copy Access

source_user, target_user

All other variables

 

 

Alternative, You can achieve it using single onChange  catalog Client script ( field is Request Type) 

Other visibility -you can control using script ( if coding is fine for you)

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

yashkamde
Mega Sage

Hello @vodnalar26 ,

 

I'd recommend pick one approach only, deleting the client script and using 7 declarative UI Policies instead, one per Request Type value, each explicitly setting Visible/Mandatory true for the two relevant fields and false for the other five.

 

If my response help mark as helpful and accept the solution.

Divya Rajasekar
Tera Contributor

Hi,

 

I would suggest you to go with UI policies.

1. To hide all fields first with highest priority(lowest number)

2. To create UI policies for common fields that is present in one or more request_type.

3. To create UI policies for independent fields for each type.