Show UI Action form button during choice field on change

Andrew48
Kilo Explorer

Hello Snowers,

I have a UI Action form button "Send Notification", which has to be shown only when a certain value is chosen from the status choice list. 

I have provided the condition but it is working only when the form is loading. is there a way to make this happen without saving the form and reloading it.

find_real_file.png

The UI Action i configured.

find_real_file.png

Also a clarification, does the UI action form button gets executed only during a form load?

10 REPLIES 10

AbhishekGardade
Giga Sage

Hello Andrew,

1) Create a UI Policy --> Set Condition as field (check_box) is true

2) In the Script tab set Run scripts true

3) In the if condition write        

                  $$('#action_name')[0].hide();     //This will hide the top button

                  $$('#action_name')[1].hide();     //This will hide the bottom button as well

4) In the else condition write        

                  $$('#action_name')[0].show();     //This will show the top button

                  $$('#action_name')[1].show();     //This will show the bottom button as well

 

For reference,

check this How to hide/show an UI action on field changes

Also Refer this nice blog 

https://www.servicenowguru.com/scripting/client-scripts-scripting/removing-form-buttons/

In addition to above, You may look on this solution by one of the community Expert:

How to hide/show an UI action on field changes

NOTE For all above mentioned solutions :

With London, new client side scripts like UI POLICY AND CLIENT SCRIPTS are executed in strict mode which means you cannot run scripts that contains any of DOM objects like gel or jQuery or prototype or window objects or document.getElementByID.

Service Now has introduced a new field labelled "Isolate script" on all client side scripts like Client scripts, UI Policies, UI Actions, Catalog Client Scripts, Catalog UI Policies and it is set to TRUE for all new configurations. If you want to get your script running, you need to change its value to FALSE. This field is not displayed on form but you can add it on form or list layout and then update.

Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade

Thank you,
Abhishek Gardade

In addition to above, You may look on this solution by one of the community Expert:

How to hide/show an UI action on field changes

NOTE For all above mentioned solutions :

With London, new client side scripts like UI POLICY AND CLIENT SCRIPTS are executed in strict mode which means you cannot run scripts that contains any of DOM objects like gel or jQuery or prototype or window objects or document.getElementByID.

Service Now has introduced a new field labelled "Isolate script" on all client side scripts like Client scripts, UI Policies, UI Actions, Catalog Client Scripts, Catalog UI Policies and it is set to TRUE for all new configurations. If you want to get your script running, you need to change its value to FALSE. This field is not displayed on form but you can add it on form or list layout and then update.

Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade

Thank you,
Abhishek Gardade

Hi Abhishek,

Thanks for your response.

I tried using the same code in a client script, as there was a onchange client script present already, 

Even after i checked the isolate script check box, i am facing the below error.

TypeError: $$ is not a function function () { [native code] }

I used this code "$$('send_notification')[0].show(); "

kindly help.

 

Hello Andrew,

Have you tried this code?

How to hide/show an UI action on field changes

I will try to find a bug as you mentioned.

Thanks,

Abhishek Gardade

Thank you,
Abhishek Gardade