Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Why UI page popup window is not getting close after clicking on Submit button?

Virendra K
Kilo Sage

Hi All,

 

I have created UI page to accept user rejection reason input while rejecting the approval.

Scenario 1 : working fine.

     - When I am rejecting the approval from the Related List >> Approvers tab then UI page is getting close after clicking on "Submit" button ( snap )

     

VirendraKharka_0-1716468994431.png

 

Scenario 2 : NOT working.

     - When I am rejecting the approval from the separate browser then UI page is NOT getting close after clicking on "Submit" button ( snap )

       

VirendraKharka_1-1716469177356.png

 

What may be the reason for this behavior ? 

@Ankur Bawiskar seeking your expertise here ?

 

 

 

UI Action:

VirendraKharka_2-1716469396509.png

 

Below is the code :

UI Page : reject_approval_chg_nj

 

HTML: 

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

    <br/>
        <g:form_label>Enter Rejection Reason: </g:form_label>
        <input name="add_message" id="add_message" style="display:block; margin-bottom:10px; width:100%"/>
        <g:dialog_buttons_ok_cancel ok_id="submitData" ok="return continueOK()" ok_type="button" ok_text="Submit" ok_style_class="btn btn-primary" cancel_type="button" cancel_id="cancelData" cancel_style_class="btn btn-default" cancel="return continueCancel()"/>
    </g:ui_form>
   
</j:jelly>
 
Client script:
function continueOK() {
    var gdw = GlideDialogWindow.get();
    var outageMessage = gel('add_message').value;
    // var sysNumber = g_form.getValue('number') ;
     
    var ga = new GlideAjax('MyAjaxProcessor');
         ga.addParam('sysparm_name', 'process');
         ga.addParam('sysparm_changeNum',g_form.getUniqueValue());
         ga.addParam('sysparm_comments', outageMessage);
         ga.getXMLAnswer(function(response) {
             var answer = response.responseXML.documentElement.getAttribute("answer");
              gs.log('Vir MyAjaxProcessor answer '+ answer );
             if (answer == 'success') {
                 alert('Comments submitted successfully');
                 window.location.reload();
             } else {
                 alert('Error: ' + answer);
             }
         });
    //window.location.reload();
    GlideDialogWindow.get().destroy();
}
function continueCancel() {
    GlideDialogWindow.get().destroy();
    return false;
}
 
 
Script Include: 
 Name: MyAjaxProcessor
Client Callable = Yes
 
   var MyAjaxProcessor = Class.create();
   MyAjaxProcessor.prototype = Object.extendsObject(AbstractAjaxProcessor, {
       process: function() {
           var chg = this.getParameter('sysparm_changeNum');
           var comments = this.getParameter('sysparm_comments');
            // gs.log('Vir MyAjaxProcessor Ln6 ' + comments );
            // gs.log('Vir MyAjaxProcessor Ln7 ' + chg );
           var approvalRecord = new GlideRecord('sysapproval_approver');
            approvalRecord.addQuery('sysapproval',chg);
            //gs.log('Vir MyAjaxProcessor query ' + approvalRecord.addQuery('sysapproval',chg));
            approvalRecord.query();
           if (approvalRecord.next()) {
              // gs.log('Vir MyAjaxProcessor Passed ' );
               approvalRecord.comments = comments;
               approvalRecord.state='rejected';
               approvalRecord.update();          
               return 'success';
           } else {
               return 'error: record not found';
           }
       }
   });

 

 

Regards,

VIrendra

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Virendra K 

line 66 won't work as it's server side code and your function is client side

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

Thanks for your quick reply @Ankur Bawiskar 

Could you please be more specific which line you r talking about ? I didnot get.