How to disable an UI action through Client Script?

Ankita Mondal
Tera Contributor

I have tried disabling the UI action in a onChange client script through the below code:

g_form.setDisabled('request_approval', true);
 
but this is not working,
can anyone suggest any alternatives?
2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Ankita Mondal You will not be able to disable UI Action using setDisabled as no such method on g_form.setDisabled doesn't exist.

 

Following is the way you should disable the UI Action via script.

 

Create an onLoad script on the form where you would like to disable the UI Action.

Screenshot 2023-11-08 at 7.35.41 AM.png

 

 

 

//Disable the 'request_approval' button
    var items = $$('BUTTON').each(function(item) {
        if (item.innerHTML.indexOf('Request Approval') > -1) { //replace Request Approval with the name of your UI Action
            item.disable();
        }
    });

 

 

 

Here is the end result.

Screenshot 2023-11-08 at 7.33.31 AM.png

Hope this helps.

Weird
Mega Sage

So depending on a selection on the form you wish to hide an UI action?
setDisabled is for fields, so it's not going to work on an UI action.
I doubt there's any direct way for you to disable an UI action with g_form.

Here's an example from Servicenow on hiding a UI action
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0697296

I'll add what the resolution says in case the link ever breaks:

For our UI action name "test". In order to hide both the top and bottom UI actions. We need to input the following into the corresponding UI policy "Execute if True" and "Execute if False" fields.

Execute if True: 
function onCondition() { 
$j('[data-action-name=test]').show(); 
} 

Execute if False: 
function onCondition() { 
$j('[data-action-name=test]').hide(); 
}