Disable UI Button In Workspace

viknesh3
Tera Contributor

How can we disable UI button after clicking it once in Scoped application.

1 REPLY 1

sumanta pal
Kilo Guru

To disable a UI button after clicking it once in a Scoped application in ServiceNow, you can use client-side scripting. Here are the steps:

1. Create a UI Script:
- Navigate to System UI > UI Scripts.
- Click on New to create a new UI script.
- Give it a name and description.
- In the script field, write a JavaScript function to disable the button. For example:
javascript
function disableButton(buttonId) {
var button = document.getElementById(buttonId);
if (button) {
button.disabled = true;
}
}

- Make sure the script is set to "Global" if you want it to be accessible from all applications.

2. Call the UI Script from a Client Script:
- Navigate to System Definition > Client Scripts.
- Click on New to create a new client script.
- Select the table and type (OnLoad, OnSubmit, etc.) as per your requirement.
- In the script field, call the UI script function with the ID of the button you want to disable. For example:
javascript
function onLoad() {
disableButton('sysverb_new');
}

- Make sure the client script is in the same application scope as the UI script if the UI script is not global.

3. Test the functionality:
- Navigate to the form where the button is located.
- Click on the button and it should be disabled after the first click.

Please note that the button will be enabled again once the page is refreshed or reloaded. If you want to keep the button disabled even after page reload, you will need to store the button state in a database or a cookie.


nowKB.com