How to disable a button on the form?

Johannes Mweli
Giga Guru

Hi ServiceNow Community Developers,

 

Do you know if there is a way to make a form button read only (unclickable / greyed out) but still keep it on the form when the conditions for it to be clickable are not me. Basically I have a requirement to not hide the button when the conditions are not met but keep it on the form but make it unclickable. OOB behavior is you hide the button when the conditions for it to appear are not satisfied so that is not scaling well for me with this requirement.

 

Would you please advise if this is possible in ServiceNow and how can I accomplish it. 

 

Thanks,

Johannes

 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Johannes Mweli Try the following script.

Screenshot 2023-11-08 at 7.35.41 AM.png

//Disable the 'Submit' button
    var items = $$('BUTTON').each(function(item) {
        if (item.innerHTML.indexOf('Create New Incident') > -1) {
            item.disable();
        }
    });

Here is the end result.

Screenshot 2023-11-08 at 7.33.31 AM.png

Hope this helps.

View solution in original post

4 REPLIES 4

AshishKM
Kilo Patron
Kilo Patron

Hi @Johannes Mweli ,

You can play with required condition which make it disable on form, there should be filed value on the form which required in the same state along with other condition to be fulfill for enable/disable this UI Action button. 

Share mode details like form, table and condition.

 

-Thanks

Ashish


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Sandeep Rajput
Tera Patron
Tera Patron

@Johannes Mweli Try the following script.

Screenshot 2023-11-08 at 7.35.41 AM.png

//Disable the 'Submit' button
    var items = $$('BUTTON').each(function(item) {
        if (item.innerHTML.indexOf('Create New Incident') > -1) {
            item.disable();
        }
    });

Here is the end result.

Screenshot 2023-11-08 at 7.33.31 AM.png

Hope this helps.

Good one @Sandeep Rajput  👍 , hope this will help to @Johannes Mweli 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Thank you so much @Sandeep Rajput it worked.