Hide/Show UI Action in Client Script

ican
Tera Contributor

Use Case:
I have a UI Action and I want to hide/show it based on a field form value.

OR

How to rename UI Action in client script?

 

How to do this?

 

Thanks.

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @ican,

 

Best practice and the easiest way would be to leverage the UI Action 'Condition' field.

A simple example and syntax would be as follows:

 

current.state == 3 // where the state field value is equal to 3. You can add additional conditions by simply using ''&&' current.fieldname etc 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.

 

Thanks, Robbie

View solution in original post

9 REPLIES 9

Dr Atul G- LNG
Tera Patron
Tera Patron

Try this @ican 

 

https://www.servicenow.com/community/itom-forum/displaying-ui-action-based-on-the-value-in-fields/m-...

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

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

Paul Curwen
Giga Sage
  1.  Create a UI Policy --> Set the Condition in the When to Apply section for your field.
  2.  In the Script tab set Run scripts true.runscripts.PNG
 

3. In the Execute if true section, write. $$('#action_name')[0].hide(); //This will hide the button. ..

4. In the Execute if  false section write. $$('#action_name')[0].show(); //This will show the  button.

 

the action_name is the action_name of the ui_action you want to hide. If it is blank set it to a value of your choice

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

ican
Tera Contributor

I tried this and im having this error: $$ is not a function

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

To show / Hide UI Action, why dont you add the logic in the ui action's condition?

-Anurag