How to hide/show a UI action button based on change in value of a field on a form?

sowmyarajaram
Tera Expert

Hello All,

Is there a way to hide/show UI action button based on change in value of a field on a form?

Sowmya

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

UI actions condition are evaluated on form load; so if you want to show/hide UI action on field change; you need to use onchange client script; ensure isolate script is set to false for that client script

you would require dom manipulation for this;

Sample script below:

if(value == 'Yes'){

var items = $$('BUTTON').each(function(item){
   if(item.innerHTML.indexOf('UI Action Title') > -1){
      item.hide();
   }
});

}

else if(value == 'No'){

var items = $$('BUTTON').each(function(item){
   if(item.innerHTML.indexOf('UI Action Title') > -1){
      item.show();
   }
});

}

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Yep, but on client script how can we achieve this? DOM is now not recomended and doesn't work too in Newyork. Alos what do you mean by isolate script is set to false?

 

Sowmya

Hi,

check isolate script to false from list layout; other than DOM you cannot achieve this on change show/hide the UI action

screenshot below for isolate script field to false

find_real_file.png

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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