RITM Approval History
Overview
This Email Script generates a formatted approval history table for email notifications sent to stakeholders regarding Requested Item (RITM) approvals.
The script iterates through approval records linked to an RITM and displays each approver’s name, decision (approved/rejected/requested), and action timestamp in chronological order.
Use Case
When an RITM is approved, rejected, or receives new approvers, stakeholders receive a notification email. This script populates the email body with a complete audit trail of all approval activity, ensuring recipients have full visibility into the approval workflow without logging into ServiceNow.
To actual use the script in an email notification you can use this ${mail_script:scriptName} syntax in the email template, where scriptName is the name of this Email Script record.
Implementation
Overview
The script queries the sysapproval_approver table for all approvals related to the current RITM record. It filters for approvals in approved, rejected, and requested states and sorts chronologically, and formats each entry for email display.
Parameters
current— the RITM record (containssys_id)template— email template object used to render contentemail— email objectemail_action— action trigger informationevent— event context
Script
| |
How It Works
Step 1: Initialize Query
A GlideRecord query on sysapproval_approver establishes the baseline for fetching approval records related to the current RITM.
| |
This handles multiple approval linkage patterns (direct sysapproval reference or document reference).
Step 2: Filter For Valid Approvals
The query filters for:
- Approvals with a non-null
approver(ensures approver is assigned) - States of
approved,rejected, orrequested
| |
Step 3: Sort By Timestamp
Results are sorted chronologically by sys_updated_on, presenting the approval history in the order decisions were made.
| |
Step 4: Apply Limit
A configurable limit (default 20) prevents extremely long emails for items with many approvers. An overflow message notifies the recipient if additional approvals exist.
| |
Step 5: Render Output
For each approval, the script prints:
| |