UI - Action -Manager Override
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 08:45 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 12:00 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 12:52 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 01:25 AM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 09:10 PM - edited 02-17-2025 09:11 PM
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