pr8172510
Tera Guru

 

Hi Roshini,

I tried your approach and was able to fix the OK button issue  (it was due to missing return in the dialog button / submission handling).

However, I’m still facing an issue with the record update part:


 Current Behavior

  • Popup opens correctly 
  • Validation works (empty reason is blocked) 
  • On clicking OK → dialog closes 

 But:

 

 
State → NOT changing 
Stage → NOT updating 
Work notes → NOT getting updated 
 

 

 What I Observed

Even though the processing script runs, the RITM remains:

 

 
State = Open
Stage = Waiting for Approval
 

Looks like something is overriding or blocking the update.


function cancelRITM() {

 

    var dialog = new GlideDialogWindow('cancel_reason_dialog');

    dialog.setTitle('Cancellation Reason');

    dialog.setSize(600, 300);

 

    dialog.setPreference('sys_id', g_form.getUniqueValue());

 

    dialog.render();

}



<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">

 

<g:ui_form method="post" action="cancel_reason_dialog.do">

 

    <input type="hidden" name="sysparm_name" value="cancel_ritm" />

    <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>

            <td align="right">

                <button type="button" onclick="submitForm()">OK</button>

                <button type="button" onclick="cancelDialog()">Cancel</button>

            </td>

        </tr>

    </table>

 

</g:ui_form>

 

</j:jelly>





function submitForm() {

 

    var reason = gel('cancel_comments').value;

 

    if (!reason || reason.trim() == "") {

        alert("Cancellation reason is mandatory.");

        return false;

    }

 

    document.forms[0].submit();

}

 

function cancelDialog() {

    GlideDialogWindow.get().destroy();

    return false;

}




if (request.getParameter('sysparm_name') == 'cancel_ritm') {

 

    var sys_id = request.getParameter('sys_id');

    var cancel_comments = request.getParameter('cancel_comments');

 

    var gr = new GlideRecord('sc_req_item');

 

    if (gr.get(sys_id)) {

 

        if (!cancel_comments || cancel_comments.trim() == "") {

 

            gs.addErrorMessage("Cancellation reason is mandatory.");

            response.sendRedirect("cancel_reason_dialog.do?sys_id=" + sys_id);

 

        } else {

 

            gr.state = 4; // Closed Incomplete

            gr.work_notes = "Cancelled: " + cancel_comments;

            gr.update();

 

            gs.addInfoMessage("RITM cancelled successfully");

 

            response.sendRedirect("sc_req_item.do?sys_id=" + sys_id);

        }

    }

}

Screenshot 2026-04-13 183722.pngScreenshot 2026-04-13 183820.png