Hide a UI action once comments are added
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 06:24 AM
Hi All,
I wanted to know how can we achieve below:
I want to hide a button from the form (say Review button on change form) once comments are added on it.
There is no state change. I cannot also no make the comments field read only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 07:17 AM
Hi @Saloni Dhanoti1,
To achieve hiding a button on a form in ServiceNow when comments are added, you can use client scripts and UI actions-
Step 1: Client Script:
Type - onChange
Field name - Comments
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.removeButton('review');
}
Step 2: UI Action:
1. Navigate to: System Definition > UI Actions.
2. Find the Review button: Search for the UI action that represents the Review button.
3. Modify the condition: Ensure that the UI action condition allows the button to be removed by the client script.
If you want to ensure the button can be dynamically shown or hidden, you can add a check in the UI action script to ensure it only appears under the right conditions.
Script:
if (!current.comments.nil())
{
current.setDisplay(false);
}
This solution leverages ServiceNow's client scripts to dynamically hide a button when a specific field changes. Ensure that the field names and button names match those used in your ServiceNow instance. You may need to adapt the scripts slightly based on your specific configuration and requirements.
Please mark helpful, if you accept the solution.