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

Hi @Ankur Bawiskar 

I have done as said by you . But still I am not getting expected result . Can you please check onChange client script code .

 

Thanks in advance

find_real_file.png

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('carear_instruct') > -1) {
                item.show();
            }
        });
    }
	else {
		var itemss = $$('BUTTON').each(function(item) {
            if (item.innerHTML.indexOf('carear_instruct') > -1) {
                item.hide();
            }
        });
	}

    //Type appropriate comment here, and begin script below

}

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

Musab Rasheed
Tera Sage
Tera Sage

Hello,

If you are fine with my response, 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

RaghavSh
Kilo Patron
$$ might not work here , you may need to use this.jQuery() but before that check your console by inspecting the page, if it is not working some error should surely be logged there

Raghav
MVP 2023