The CreatorCon Call for Content is officially open! Get started here.

Disable a button or make it readonly

Not applicable

Hi , I have added a new button on the form and its corresponding action. works good. I need to make it appear active conditionally on the form but not hide it. Just to make it disabled when the condition does not meet and not completely hide. Instead, show it but should not be active.
something like if(condition) (button.disabled=true) else (button.disabled=false)
I know this can be achieved through script, but how to grab the button id/name.

Thanks,
Shiva

14 REPLIES 14

poornima2
Mega Expert

I found some scripts regarding disabling form button,
http://www.servicenowguru.com/scripting/client-scripts-scripting/removing-form-buttons/


Jay_Ford
Kilo Guru

You can also call the button element itself. For example if your buttons name is 'Test Me', you could do the following in an onChange or onLoad client script. The button id ends up being your button name with _ instead of spaces, and all lower case (in this case test_me).



var it = document.getElementById('test_me');
it.disabled = true;
it.style.backgroundColor = '#cccccc';


Not applicable

Hi Jay,
Thank you for the replies. I tried doing it that way but still the button doesnt get disabled, not sure why. Even i tried using the code
g_form.getControl(name). Perhaps because there are other ui actions/policies associated with that button. Dont know.

Thank you poornima, for sharing that service-now guru link. That site is a useful source of information.



If you still don't have this working, could you post the javascript you are using for the client script.