Hide button with onChange Client Script?

Edwin Fuller
Tera Guru

I have the below script that is currently not working. I need to hide the "Complete Task" button if the state changes to any of the following. "-940", "-941", "-942", "-943". Can someone help me correct this script?

function onChange(){

      //If the incident type is 1,2,3

}

showCloseTaskButton('Convert to Request');

function showCloseTaskButton(button) {

      if(g_form.getValue('state' == -940) || g_form.getValue('state' == -941 || g_form.getValue('state' == -942) || g_form.getValue('state' == -943)){

           

           

              //show the 'Convert to Request'

           

              var items = $$('BUTTON').each(function(item){

                      if(item.innerHTML.indexOf('Complete Task') > -1){

                              item.show();

                      }

                   

              });

      } }

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

Hi Edwin,



if you want to make your ui action visibility based on dropdown values then you can try with UI Policy.



refer the screenshot below. i tested with category values. button will be visible based on category values.


find_real_file.png



find_real_file.png




Script :



function onCondition() {



$$('#awc_test')[0].show();



}


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



function onCondition() {



$$('#awc_test')[0].hide();



}



Hope it will help you.


View solution in original post

17 REPLIES 17

Dave Smith1
ServiceNow Employee
ServiceNow Employee

Edwin Fuller wrote:



I have the below script that is currently not working. I need to hide the "Complete Task" button if the state changes to any of the following. "-940", "-941", "-942", "-943". Can someone help me correct this script?


Does it need to be a script?



I can see using a condition:


find_real_file.png


.. however, this won't work dynamically if the state changes whilst looking at it.



Could you use a UI Policy to conceal the visibility instead?


I actually need for it to work dynamically because the users manually update the state field


divya mishra
Tera Guru

Hey Edwin,



You can better do this on the condition part of the button itself.



like :   (current.state != "-940") || (current.state != "-941") and so on.


pastedImage_1.png




post me your feedback


Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


Have a lovely day ahead




Regards,


Divya Mishra


divya mishra
Tera Guru

Hey Ed,



any updates ?



Regards,


Divya


Harsh Vardhan
Giga Patron

Hi Edwin,



if you want to make your ui action visibility based on dropdown values then you can try with UI Policy.



refer the screenshot below. i tested with category values. button will be visible based on category values.


find_real_file.png



find_real_file.png




Script :



function onCondition() {



$$('#awc_test')[0].show();



}


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



function onCondition() {



$$('#awc_test')[0].hide();



}



Hope it will help you.