UI - Action -Manager Override

faisal_waryum
Tera Expert

Hi Everyone, 

I have created a UI Action - Approval Override which lets our servicedesk agents override the manager approval when a request is urgent. 

the issue i am having is that when the agent select the UI Action along the top the approval generates for the user who has selected the UI Action but the manager approval is still in the requested stage. 

I have this script which i think i am missing something if someone can offer some guidance please

// Client-side execution
if (typeof window !== 'undefined') {
var submitFlag = confirm("Creating Adhoc Approver will Override all Approvals");
if (!submitFlag) {
return false; // Abort if user cancels
}
gsftSubmit(null, g_form.getFormElement(), 'override_approval');
}

// Server-side execution
else {
var approvalGr = new GlideRecord("sysapproval_approver");
approvalGr.addQuery("sysapproval", current.sys_id); // Find approvals related to this request
approvalGr.addQuery("approver.role", "manager"); // Target the Line Manager's approval
approvalGr.query();

if (approvalGr.next()) {
approvalGr.state = "approved"; // Override approval
approvalGr.update();
gs.addInfoMessage("Line Manager approval overridden.");
} else {
gs.addInfoMessage("No Line Manager approval found to override.");
}

current.u_approval_override = true;
current.update();
action.setRedirectURL(current);
}



7 REPLIES 7

@Jim Coyne 

2. what do you mean by "the approval generates for the user who has selected the UI Action"?  A new Approval record was created?
Yes a new approval is generated and then the servicedesk agent who has selected the UI Action will be able to approve the REQ 

4. If it were me, I'd be adding a new approved Approval record with something in the comments for the current user instead of approving someone else's. Not great audit-wise
How do i do this then ? 

 

 

 

sunil maddheshi
Tera Guru

@faisal_waryum 

Try with below updated code:

// Client-side execution
if (typeof window !== 'undefined') {
    var submitFlag = confirm("Creating Adhoc Approver will Override all Approvals");
    if (!submitFlag) {
        return false; // Abort if user cancels
    }
    gsftSubmit(null, g_form.getFormElement(), 'override_approval');
}

// Server-side execution
else {
    var approvalGr = new GlideRecord("sysapproval_approver");
    approvalGr.addQuery("sysapproval", current.sys_id); // Find approvals related to this request
    approvalGr.addQuery("state", "requested"); // Only override approvals that are still pending
    approvalGr.query();

    var overridden = false; // Flag to check if any approvals were updated

    while (approvalGr.next()) {
        var approverUser = approvalGr.approver;
        var manager = new GlideRecord('sys_user');
        if (manager.get(current.requested_for.manager)) { // Check if the approver is the requester's manager
            if (approverUser == manager.sys_id) {
                approvalGr.state = "approved"; // Override approval
                approvalGr.update();
                overridden = true;
            }
        }
    }

    if (overridden) {
        gs.addInfoMessage("Line Manager approval overridden.");
    } else {
        gs.addInfoMessage("No pending Line Manager approval found to override.");
    }

    current.u_approval_override = true;
    current.update();
    action.setRedirectURL(current);
}

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for

faisal_waryum
Tera Expert

i took another avenue where i created a new group and gave this group the admin override ability with the config set up to X job title. 
the business rule also on the sysapproval_approver table which checks and if X user approves then there is a comment to mention the override