How to hide UI action button on change of field value

Supriya20
Tera Expert

Hi All,

We have a requirement to hide "request approval" button on change request form, based on the selection of field "Type" If the type is comprehensive then we need to hide RequestApproval button. 
UI action is working only for onload. So I tried using DOM manipulator in client script. but it is trowing some error's. Please let me know, how to achieve this.

Script:

document.getElementById("requestapproval").style.display = 'none'; 

Error:

find_real_file.png

 

Thanks,

Supriya.

1 ACCEPTED SOLUTION

Hi,

try this in the onChange client script of Type field

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    
    if (newValue == 'comprehensive') {
        var items = $$('BUTTON').each(function(item) {
            if (item.innerHTML.indexOf('Request Approval') > -1) {
                item.show();
            }
        });
    }
	else {
		var itemss = $$('BUTTON').each(function(item) {
            if (item.innerHTML.indexOf('Request Approval') > -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

11 REPLIES 11

@Ankur Bawiskar  This code is not working for me and i am getting "script error encountered when changing this field - please connect system administrator" error below the field on which we are writing the script

 

Hi @Ankur Bawiskar I tried your script but it's not working to me

I want to show UI button "Plan Document Team Request" on form when

the field "Plan Document Analysis" value 'yes'

Let me know what Iam doing wrong

 

Thaks in Advance!!!

 

Regards

APV Babu