Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

UI action not cancelling for ui page

nwosuja66
Tera Contributor

Hi All,

I have a requirement to create a dialog box to handle cancellation reason and i created a ui page which works.

But, the ui action i have used the existing OOTB ui action script and modified it to call my ui page but it doesn't submit when i click the cancel button:

ui page

 

UI page script:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null">
 
<g:ui_form>
  <table>
    <!-- Header -->
    <tr>
      <td colspan="2" style="font-weight:bold; font-size:18px; padding-bottom:15px">
        Cancel request
      </td>
    </tr>
 
    <!-- Cancellation reason (choice list) -->
    <tr>
      <td style="width:30%">
        <g:form_label>Cancellation reason:<span style="color:#d00">*</span></g:form_label>
      </td>
      <td style="width:75%; padding-left:10px;">
        <g:ui_choicelist
            name="u_cancellation_reason"
            id="u_cancellation_reason"
            table="sn_lg_ops_legal_request"
            field="u_cancellation_reason"
            mandatory="true"
            query="active=true"
            style="width:100%" />
      </td>
    </tr>
 
    <tr><td colspan="2" style="height:10px"></td></tr>
 
    <!-- Work note -->
    <tr>
      <td style="width:30%">
        <g:form_label>Work note:</g:form_label>
      </td>
      <td style="width:70%">
        <textarea name="work_notes" id="work_notes" rows="4" style="width:100%"></textarea>
      </td>
    </tr>
 
    <!-- Buttons -->
    <tr>
      <td colspan="2" style="text-align:right; padding-top:16px">
        <g:dialog_buttons_ok_cancel
            ok_id="submitData"
            ok="return continueOK()"
            ok_text="Cancel request"
            ok_type="button"
            ok_style_class="btn btn-primary"
            cancel_id="cancelData"
            cancel="return continueCancel()"
            cancel_type="button"
            cancel_style_class="btn btn-default" />
      </td>
    </tr>
  </table>
</g:ui_form>
</j:jelly>
 

ui page client script:

 

function continueOK() {
  var gdw = GlideDialogWindow.get();
  var reason = gel('u_cancellation_reason').value;
  var notes = gel('work_notes').value;
 
  if (!reason) {
    alert("Cancellation reason is required.");
    return false;
  }
 
  // Pass the values back to the form via hidden fields
  g_form.setValue('u_cancellation_reason', reason);
  g_form.setValue('work_notes', notes);
  g_form.save();
  return true;
}
 
function cancelAndClose() {
 
  GlideDialogWindow.get().destroy();
  return false;
}
 

ui action client script:

 

function cancelRequest() {
  var gDialog = new GlideModal('sn_lg_ops_u_cancel_request_dialog'); // Reference your UI Page name
  gDialog.setPreference('sysparm_table', g_form.getTableName());
  gDialog.setPreference('sysparm_sys_id', g_form.getUniqueValue());
  gDialog.render();
 
  if (typeof window == 'undefined')
    serverCancelRequest();
}
 
function serverCancelRequest() {
  var hasApprovals = new sn_lg_ops.LegalAdhocApprovalUtils().hasPendingApprovals(current.sys_id);
  var canCancel = new RequestUtil().canCloseOrCancelRequest(current);
  var isValidCategory = (current.lg_category != LegalOpsConstants.CATEGORY_STOCK_PRECLEARANCE &&
                         current.lg_category != LegalOpsConstants.CATEGORY_COI &&
                         current.lg_category != LegalOpsConstants.CATEGORY_GIFTS_AND_ENTERTAINMENT);
 
  if (canCancel) {
    if (hasApprovals && isValidCategory) {
      gs.addErrorMessage(gs.getMessage('The approval is in progress for the legal request. Close all approvals before cancellation.'));
    } else {
      if (current.comments) {
        new LegalRequest(current).cancel(current.comments);
      } else {
        gs.addErrorMessage(gs.getMessage('Enter comments and cancel the request.'));
      }
    }
  } else {
    gs.addErrorMessage(gs.getMessage('Close all associated matters to cancel the request.'));
  }
 
  action.setRedirectURL(current);
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@nwosuja66 

so what debugging did you do?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I was able to fix this. Thanks for your response