Skip to content
Auto-Approve via Delegate or Duplicate

Auto-Approve via Delegate or Duplicate

Overview

These two Business Rules both run on insert/update of sysapproval_approver and automatically close out an approval record as approved when a real approval decision has already effectively been made elsewhere, so the same approver isn’t pestered twice or blocked on a delegate who already acted for them.

  1. Delegate Approval Check — checks the sys_user_delegate table for an active delegate relationship for the current approver. If that delegate has already approved the same document (matched on document_id or sysapproval), the current approval record is auto-approved with a work note explaining it was “No Longer Required” because the delegate already acted.
  2. Duplicate Approval Requests — checks whether the same approver already has an approved record for the same document. If so, this (presumably duplicate) approval record is auto-approved with a work note explaining it was “Not Longer Required” due to the earlier approval on the same record by the same user.

Problem Statement

Approval workflows can generate more than one sysapproval_approver record pointing at the same underlying document for the same person — for example, if a delegate relationship is set up mid-flight, or if a workflow re-triggers approvals. Without these checks, an approver (or their delegate) could be asked to approve the same thing multiple times, or a pending approval could sit unresolved even though an equivalent approval already happened. Both rules resolve this by watching for a matching prior approved record and short-circuiting the new one to approved automatically.

Delegate Approval Check.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * Script Name: Delegate Approval Check
 * Description: This script checks if a delegate has previously approved the same record for the out-of-office user. 
 *              If a previous approval by a delegate is found, the approval is marked as 'approved', and a work note is added.
 * 
 * Usage: This script is utilized within the ServiceNow instance as a Business Rule. It is triggered when an approval request is created or updated.
 *      Example record:
 *         Name: Delegate Approval Check
 *         Table: sysapproval_approver 
 * 
 * Context: This script is intended to be used in the context of ServiceNow's approval process. It is designed to prevent redundant approvals when a delegate has already approved for the user.
 * 
 * Author: Konner Lester
 * Date Created: 05/07/2025
 * Last Modified: 05/07/2025
 * 
 */

// Execute the check
checkDelegateApproval();

function checkDelegateApproval() {
  // Ensure there is a record linked to the approval
  if (current.document_id || current.sysapproval) {
      
      // Query the sys_user_delegate table to find the delegate relationships
      var delegateGr = new GlideRecord('sys_user_delegate');
      delegateGr.addQuery('user', current.approver);
      delegateGr.addEncodedQuery('ends>=javascript:gs.beginningOfToday()');
      delegateGr.query();

      // If there is a delegate relationship, check for prior approvals
      while (delegateGr.next()) {
          var delegateUser = delegateGr.delegate;

          var approvalGr = new GlideRecord('sysapproval_approver');
          
          if (!current.document_id.nil()) {
              approvalGr.addQuery('document_id', current.document_id);
          } else if (!current.sysapproval.nil()) {
              approvalGr.addQuery('sysapproval', current.sysapproval);
          }
          
          approvalGr.addQuery('approver', delegateUser); // Look for approvals from the delegate
          approvalGr.addQuery('state', 'approved');
          approvalGr.query();
          
          if (approvalGr.next()) {
              // If a previous approval is found by the delegate, set this approval to 'approved'
              current.state = 'approved';
              current.u_work_notes = "Approval marked by system as 'No Longer Required' because the delegate (" + delegateUser.getDisplayValue() + ") approved in an earlier stage.";
              break; // Exit loop if we find a valid delegate approval
          }
      }
  }
}
Both rules match on document_id when present and fall back to sysapproval — the two fields ServiceNow uses depending on which approval engine (legacy Workflow vs. Flow Designer) generated the record.
Last updated on