Popup for cancel confirmation not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I am trying to create a UI Action with name 'Cancel RITM', which will be asking for reason for cancellation, and cancel /Ok button. Once Ok is clicked, it will verify if there is some value or not, if no value it will give an info message and won't allow to proceed further, If value is there it will allow to make the RITM closed incomplete( value =4) and update the work notes with "Cancelled: " + cancel comments.
Below is the UI action and Ui page am trying, but it is not working as expected, am not getting any error.
Just the OK button is not validating anything and updating anything. It is redirecting to "ui_page_process" page with UI action sys id.
Ui action
Ui page
HTML
Client script
Processing script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
47m ago
Hi @Roshini
Did you check your logs to know whether your logic enters into process script or check sys_id is correctly grabbed from form ?
I checked the code it seems fine ,
you can try: : return validateReason() for below and check once
Thanks and Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
46m ago
There are a few interconnected issues causing this behavior.
Root cause: The OK button submits the form regardless of your validation return value. When you use ok_type="submit", the g:dialog_buttons_ok_cancel macro fires a native form submit. Your validateReason() runs, but its return false doesn't actually prevent the POST — the form submits anyway, which is why you see the redirect to ui_page_process.do.
The second issue is in the processing script — sys_id and cancel_comments aren't available as bare variables. You need to pull them from the request parameters.
Here's the corrected code for all three pieces:
UI Action (Client Script) — no changes needed here:
function cancelRITM() {
var dialog = new GlideDialogWindow('cancel_reason_dialog');
dialog.setTitle('Cancellation Reason');
dialog.setSize(750, 300);
dialog.setPreference('sys_id', g_form.getUniqueValue());
dialog.render();
}
UI Page HTML — switch OK to button type and submit manually:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:ui_form>
<input type="hidden" name="sys_id" value="${RP.getWindowProperties().get('sys_id')}" />
<table width="100%">
<tr>
<td>
<p>Please provide a reason for cancellation:</p>
<textarea id="cancel_comments" name="cancel_comments" rows="4" style="width:100%"></textarea>
</td>
</tr>
<tr id="dialog_buttons">
<td align="right">
<g:dialog_buttons_ok_cancel ok="return validateAndSubmit()" ok_type="button"
cancel="cancelDialog()" cancel_type="button"/>
</td>
</tr>
</table>
</g:ui_form>
</j:jelly>
UI Page Client Script — validate first, then submit the form programmatically:
function validateAndSubmit() {
var reason = gel('cancel_comments').value.trim();
if (reason === "") {
alert("Cancellation reason is mandatory.");
return false;
}
// Manually submit the form only after validation passes
document.forms[0].submit();
return false;
}
function cancelDialog() {
GlideDialogWindow.get().destroy();
return false;
}
The key change is ok_type="button" instead of ok_type="submit". This way clicking OK only runs your function — it no longer triggers a native form submit behind your back. You then call document.forms[0].submit() yourself only when the textarea has a value.
UI Page Processing Script — use RP.getParameterValue():
var sysId = RP.getParameterValue('sys_id');
var cancelComments = RP.getParameterValue('cancel_comments');
var gr = new GlideRecord('sc_req_item');
if (gr.get(sysId)) {
gr.state = 4; // Closed Incomplete
gr.work_notes = "Cancelled: " + cancelComments;
gr.update();
}
response.sendRedirect("sc_req_item.do?sys_id=" + sysId);
The processing script runs server-side inside the UI Page's scope. The form field values come through as request parameters, so you access them via RP.getParameterValue('field_name') — the name attributes on your hidden input and textarea are what map here. Bare sys_id and cancel_comments variables don't exist in that context, which is why nothing was updating.
To summarize the three fixes: change ok_type from "submit" to "button" so validation actually gates submission, call document.forms[0].submit() manually after validation passes, and use RP.getParameterValue() in the processing script to read the posted form values.
