Stop users rejecting the approvals from the list context without adding comments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2025 09:16 PM
UI action to stop users from rejecting the approvals from list context and providing a dialog to enter comments.
Is there a way we can stop users rejecting the approvals from the list context and provide a pop up comments box to add the comments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2025 11:24 PM
Hello @PratR ,
Create the UI action and UI page to allow the comments to add
below is the sample example
1. Create the UI Action:
• Name: Choose a descriptive name (e.g., "Add Comments to Selected").
• Table: Select the table where this action will be used (e.g., Incident).
• Action name: Give it a unique action name (e.g., add_comments_to_selected).
• List UI Action: Check this box to make it available on list layouts.
• Client: Check this box to make it client-side (required for opening a pop-up).
• Onclick: Enter the name of the client-side function that will be executed when the UI Action is clicked (e.g., openCommentsDialog).
• Script: This is where the logic for opening the pop-up goes:
JavaScript
function openCommentsDialog() {
// Get the sys_ids of the selected records
var selectedRecords = g_list.getChecked();
// Check if any records are selected
if (selectedRecords.length === 0) {
alert('Please select at least one record.');
return;
}
// Initialize and open the GlideDialogWindow
var dialog = new GlideDialogWindow('add_comments_dialog'); // Name of your UI Page
dialog.setTitle('Add Comments to Selected Records');
dialog.setPreference('sysIDs', selectedRecords); // Pass selected records to the UI Page
dialog.render();
}
2. Create the UI Page (e.g., add_comments_dialog):
• Name: Match the name used in the UI Action's dialog.setPreference (e.g., add_comments_dialog).
• HTML: This section contains the form for adding comments.
Code
<div>
<textarea id="comments" name="comments" rows="4" cols="50" placeholder="Enter your comments here"></textarea>
<br/>
<button onclick="saveComments()">Save</button>
<button onclick="GlideDialogWindow.get().destroy()">Cancel</button>
</div>
• Client Script: This script handles the logic for saving the comments and closing the pop-up.
JavaScript
function saveComments() {
var comments = gel('comments').value;
var sysIDs = dialog.getPreference('sysIDs'); // Retrieve the sys_ids from the preference
// Validate that comments are entered
if (comments.trim() === '') {
alert('Please enter comments.');
return;
}
// Call a server-side script to save the comments
var ga = new GlideAjax('AddCommentsAjax');
ga.addParam('sysparm_name', 'saveComments');
ga.addParam('sysparm_sysIDs', sysIDs);
ga.addParam('sysparm_comments', comments);
ga.getXMLAnswer(saveCommentsCallback);
}
function saveCommentsCallback(response) {
var result = response.trim();
if (result === 'success') {
alert('Comments saved successfully.');
GlideDialogWindow.get().destroy(); // Close the dialog
// Optionally, refresh the list to reflect changes
g_list.refresh();
} else {
alert('Error saving comments: ' + result);
}
}
script include: AddCommentsAjax