Customized UI Page pop up on click of 'Approve' in list context menu choice list

VS_09
Tera Contributor

Customized UI Page pop up on click of 'Approve' in list context menu choice of Approvers related tab of change form.

 

On change form, when change is waiting for approval. Go to 'Approvers' related tab. right click on the approval request and once you click on APPROVE. A pop-up window should appear.

 

kaur_developer_1-1709524728592.png

Once I click on OK button, requset should be approved. But it is not working!!!!!

 

Script include: gf_ApprovalUtil

var gf_ApprovalUtil = Class.create();
gf_ApprovalUtil.prototype = {
    initialize: function() {
    },
 
    _queryMyApprovals: function(document) {
        if (!document) return;
        var grApproval = new GlideRecord('sysapproval_approver');
grApproval.addQuery('approver', 'IN',
                this.getMyApprovalDelegators().toString());
grApproval.addQuery('state', 'requested');
        if (document.getTableName() === 'sysapproval_approver') {
            grApproval.addQuery('sys_id', document.sys_id);
        } else {
            grApproval.addQuery('document_id', document.sys_id);
        }
        grApproval.query();
        return grApproval;
    },
 
    // Update state and comments on an approval record.
    _updateApproval: function(grApproval, newState, comments) {
        grApproval.state = newState;
        if (comments) {
            grApproval.comments += '\n' + comments;
        }
        grApproval.update();
    },
 
    // Update the document itself (if it's an approval), or all approvals
    // related to the document that are waiting for the user or one of their
    // delegators.
    _updateMyApproval: function(document, newState, comments) {
        if (!document || !newState) return;
        // always allow users with approval_admin role to approve on behalf of
        // others, but only if the document is an approval record
        if (gs.hasRole('approval_admin') &&
            document.getTableName() === 'sysapproval_approver') {
            this._updateApproval(document, newState, comments);
            return;
        }
        var grApproval = this._queryMyApprovals(document);
        while (grApproval.next()) {
            this._updateApproval(grApproval, newState, comments);
        }
    },
    isWaitingForMyApproval: function(document) {
        if (!document) return false;
        // always allow users with approval_admin role to approve on behalf of
        // others, but only if the document is an approval record
        if (gs.hasRole('approval_admin') &&
            document.getTableName() === 'sysapproval_approver' &&
            document.state == 'requested') {
            return true;
        }
        var grApproval = this._queryMyApprovals(document);
        return grApproval && grApproval.hasNext();
    },
 
    approveMyApproval: function(document, comments) {
        this._updateMyApproval(document, 'approved', comments);
    },
 
    rejectMyApproval: function(document, comments) {
        this._updateMyApproval(document, 'rejected', comments);
    },
    type: 'gf_ApprovalUtil'
};

 

UI Page - gf_update_approval

 

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

Do you want to Approve or Continue Reviewing request?
<table width="100%" cellpadding="0" cellspacing="0">
<tr><td align="right" nowrap="true"><br />
<g:dialog_buttons_ok_cancel ok="return validateForm()" cancel ="return OnCancel"/>
</td></tr>
</table>

</j:jelly>

 

Client Script -

 

function validateForm(){
alert('You have approved the request');
var gdw = new GlideDialogWindow.get();
var sys_id = gdw.getPreference('sys_id');
var ga = new GlideAjax('gf_ApprovalUtil');
ga.addParam('_updateApproval','Approved');
GlideDialogWindow.get().destroy();
}
 
function OnCancel(){
alert('You have cancelled the pop up window');
GlideDialogWindow.get().destroy();
}
 
UI Action -

function gf_approve() {
var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
changeConfirmApproveDialog = new dialogClass("gf_update_approval", false, 648, 250);
changeConfirmApproveDialog.setTitle(new GwtMessage().getMessage("Proceed"));
changeConfirmApproveDialog.setPreference('ok', 'approved');
changeConfirmApproveDialog.render();
}

 

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@VS_09 

so basically you want to approve all the records into related list on click of OK button in UI page?

2 things

1) your script include should be client callable without initialize function; so please correct it

2) you are not sending the current record sysId which will help you to query

It seems you are using some existing script include and trying to re-use in the Ajax

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

Yes, I need to approve the records into the related list on click of OK Button in UI Page.

 

1. I have made script include as client callable and removed the initialize function.

kaur_developer_0-1709563512847.png

Could you please help me with 2nd point?

 

Thanks

@VS_09 

you need to pass the record sysId to ajax function

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