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

Voona Rohila
Mega Patron
Mega Patron

Hi @faisal_waryum 

Try this code:

function openinc() {

    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');
}

if (typeof window == 'undefined')
    runServerCode();

function runServerCode() {
    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.");
        current.u_approval_override = true;
        current.update();
    } else {
        gs.addInfoMessage("No Line Manager approval found to override.");
    }
    
    action.setRedirectURL(current);
}

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

I tried this but now my UI Action does not work. I have attached a screenshot of it, let me know what i am doing wrong please

faisal_waryum_0-1739825554851.png

 

This script does not work either, the UI action does not work at all now. Perhaps my UI Action is setup wrong which i have done as follows:

faisal_waryum_0-1739870735463.png

 

Jim Coyne
Kilo Patron

A few things:

1. this article will help when posting code: TNT: And Formatted Code is Even Better

2. what do you mean by "the approval generates for the user who has selected the UI Action"?  A new Approval record was created?

3. There is no "role" field on the User table (which "approver" points to), so I'm pretty sure that query is returning nothing.  Do you mean the requested for's immediate manager?

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