2 minute read

Attribution

[DISCLAIMER] This is an AI-generated blog post based on a Slack conversation. I’ve created this to preserve and share the valuable knowledge discussed, here are those who contributed:
@eric
@romeo
@vk
Here’s a link to the original discussion (might be dead): Slack Discussion

How to Calculate Approval Duration in ServiceNow

When you need to track how long an approval takes from request to completion in ServiceNow, you have several technical approaches to choose from. This guide walks through the best practices for calculating approval duration based on state changes.

The Challenge

You want to measure the time it takes for an approval to move from “requested” to “approved” state. The key challenge is capturing the exact timestamp when the state first changes to “requested” and then calculating the duration when it changes to “approved.”

Solution Options

Option 1: Business Rules (Simple Snapshot Approach)

Best for: Single point-in-time calculations where you only need the final duration after approval is complete.

Implementation:

  • Create a “Duration” field on your approval table
  • Use an After Business Rule that triggers when the approval state changes to “approved”
  • Calculate the duration between the initial request time and approval time

Pros:

  • Simple to implement
  • Low performance impact
  • Good if you only need final duration data

Cons:

  • No data available until approval is completed
  • Doesn’t track intermediate state durations

Best for: When you want to track duration in every state and need historical reporting capabilities.

Why Metrics Are Ideal:

  • Automatically captures state changes without custom fields
  • Provides historical data for all state transitions
  • Built-in reporting capabilities
  • No performance impact from calculated fields

Implementation Steps:

  1. Create a Metric Definition:
    • Navigate to metric_definition table
    • Set up metric to track your approval state field
    • Configure to capture duration for each state
  2. View Metric Data:
    • Metric instances are stored in metric_instance table
    • Can be displayed as related lists on approval records
    • Use database views (like incident_metric) for reporting
  3. Find Reference Examples:
    • Search existing relationships: /sys_relationship_list.do?sysparm_query=basic_query_fromLIKEmetric&sysparm_view=
    • Look at out-of-the-box tables that already use metrics as related lists

Why to avoid: Calculated fields trigger on every record update, causing significant performance issues, especially on high-volume tables.

Option 4: Flows (Alternative Custom Approach)

When to use: If you need custom logic beyond what metrics provide.

Implementation:

  • Create custom datetime fields to capture state change timestamps
  • Use Flow to populate timestamp when state changes to “requested”
  • Calculate duration when state changes to “approved”

Handling the “Requested” Timestamp Challenge

A common issue is determining when the approval was first “requested,” since records might be created in different states.

Solutions:

  1. Use Metrics: Automatically handles this by tracking all state changes
  2. Custom Field + Flow: Create a “Requested Date” field and populate it via Flow when state first changes to “requested”
  3. Avoid using Created Date: Records may be created in states other than “requested”

Best Practice Recommendation

Use Metrics for approval duration tracking because they:

  • Require no custom field development
  • Provide comprehensive state duration data
  • Offer built-in reporting capabilities
  • Scale well with high record volumes
  • Give you flexibility for future analytics needs

Implementation Checklist

  • Create metric definition for your approval state field
  • Test metric instance generation with state changes
  • Set up related list display on approval records (optional)
  • Create database views for reporting (if needed)
  • Verify performance with your expected record volumes

This approach gives you a robust, scalable solution for tracking approval durations without the performance overhead of calculated fields or the limitations of simple business rules.