Hide / show UI action based on change of field on form

Abhijit Das7
Tera Expert

Hi everyone,

My requirement is to show and hide UI action based on change of field on form . Form that I have created on change client script but it is not working properly . Can anyone please help me.

find_real_file.png

And my UI action:

find_real_file.pngfind_real_file.png

 

Thanks in advance 

cc: @Ankur Bawiskar 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
	if(value == ''){

var items = $$('CareAR Instruct').each(function(item){
   if(item.innerHTML.indexOf('CareAR Instruct') > -1){
      item.hide();
   }
});

}

else if(value != ''){

var model  = $$('CareAR Instruct').each(function(item){
   if(item.innerHTML.indexOf('CareAR Instruct') > -1){
      item.show();
   }
});

}

   //Type appropriate comment here, and begin script below
   
}
1 ACCEPTED SOLUTION

Hi,

update as this -> give label of that button

I hope you have done this already

please make Isolate Script as False for your Client Script

If this field is not on form then from list make it false

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var val = g_form.getValue('x_care3_carear_fsm_instruct_experience');

    if (val != '') {
        var items = $$('BUTTON').each(function(item) {
            if (item.innerHTML.indexOf('CarearInstructButton') > -1) {
                item.show();
            }
        });
    }
    else {
        var itemss = $$('BUTTON').each(function(item) {
            if (item.innerHTML.indexOf('CarearInstructButton') > -1) {
                item.hide();
            }
        });
    }

    //Type appropriate comment here, and begin script below

}

regards
Ankur

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

View solution in original post

8 REPLIES 8

Musab Rasheed
Tera Sage
Tera Sage

Hello,

DOM manipulation is not recommended in Servicenow so I suggest you control visibility through UI action condition and make it work on load of form. This is what Servicenow recommends and UI visibility can be controlled when form loads and not when something changes on form.

Please hit like and mark my response as correct if that helps

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi @Musab Rasheed 

My requirement is to get it in change rather than onload.

I understand but DOM manipulation is not recommended but if you still insist go through below threads, Make sure 'Isolate script' checkbox is set to false

https://community.servicenow.com/community?id=community_question&sys_id=3cf172b8dbe3841413b5fb2439961926

https://community.servicenow.com/community?id=community_blog&sys_id=127d6269dbd0dbc01dcaf3231f961973

https://community.servicenow.com/community?id=community_question&sys_id=2cf54361db1cdbc01dcaf3231f96193c

https://community.servicenow.com/community?id=community_question&sys_id=c0a14ecddbcc58d8d82ffb2439961915

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please make Isolate Script as False for your Client Script

If this field is not on form then from list make it false

Regards
Ankur

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