The CreatorCon Call for Content is officially open! Get started here.

Display/Hide a UI Action Button Based on Form Value

Matt Grover
Tera Contributor

I've been asked to hide a UI action button on a form until a user makes a selection on a particular drop-down field.  In my case, I'm working in a global application called 'ticket', which is an extension of the task table.  Tickets are created by end-users and fielded by the help desk, which reviews them and transfers them to the appropriate type of record (incident, RITM, problem, etc.) and assigns them to the appropriate group.

The bug right now is that the transfer button can be clicked before the help desk worker actually decides what kind of record to transfer the ticket to.  I know how to restrict the button on the UI action record itself by adding a condition to the button.  However, this only works 'onLoad'.  So this method would require the help desk worker to take three actions:

  1. Select the type of record to transfer to in the drop-down
  2. Save the form
  3. Click the 'transfer' button which is now visible after re-loading the form

I'm hoping that there is a way for them to avoid clicking the save button and re-loading the form, so basically utilizing an onChange script or UI Policy.  However, in searching the community, all of the solutions involve DOM manipulation, which is not considered best practice.

Additionally, I've tried the method found here: 
https://community.servicenow.com/community?id=community_question&sys_id=2cf54361db1cdbc01dcaf3231f96...
But I'm running into the same error reported with the jquery method not being a function.

find_real_file.png

Does anyone know if this method stopped being supported in New York, or if there is any other way to show/hide a button based on another field value without reloading the form?

1 ACCEPTED SOLUTION

Miguel Donayre
ServiceNow Employee
ServiceNow Employee

Hello @Matt Grover  

Can you try adding the "Isolate script" filed to the UI Policy form and set it to false or uncheck it.

go to configure---> form layout and drag it over to the form

and run it again. 

It should be false to allow your DOM manipulation to work.

find_real_file.png

View solution in original post

15 REPLIES 15

Hema Mistry
Tera Expert

Where do I have to write script to hide and show the UI action? Above script with $$ worked for u?

Hello Hema,

I created a UI Policy, which has a tab for scripting.  If you don't see the fields for execute if true & execute if false, then you might need to check the box for 'run scripts'.  The other thing that made the $$ script work was adding the checkbox for 'isolate scripts' and making sure the box is unchecked.

 

find_real_file.png

Hema Mistry
Tera Expert

Thanks for quick reply. I am trying to hide my button on dropdown change. I m getting below error

find_real_file.png

UI script:

find_real_file.png

find_real_file.png

Matt Grover
Tera Contributor

Hello Hema,

What version of ServiceNow are you using?  I know several of the older answers on other posts have slightly different syntax than the one that worked for me.  I'm speculating that this is because ServiceNow changed some things about their UI action naming scheme in New York.

In your $$('saveExit_bottom')[0].hide() statement, have you verified that 'save_Exit' is the value of the 'action name' field on the UI Action record?

Example from my transfer button below:

find_real_file.png

 

The only other thing I can think is playing around with the array index value.  Maybe try using a [1] or a [2] instead of a [0].  You might also experiment with removing the _bottom at the end of the action name.

 

Other than that, I can't think of any troubleshooting steps to help, unfortunately.  Please let me know if any of those work out.

I am on NewYork version. Tried changing  the index value. I followed this KB article

KB0697296. Getting error on '$' only.