Skip to content

Commit 011e42d

Browse files
authored
User impersonation activity logger (#2401)
* Create README for User Impersonation Activity Logger Added README for User Impersonation Activity Logger, detailing its functionality, usage instructions, prerequisites, and dependencies. * Add user impersonation activity logging * Add screenshot to README for User Impersonation Logger * Update README by removing unnecessary sections Removed Hacktoberfest 2025 section and License information from README. * Remove user impersonation activity logging Removed user impersonation logging logic from the script.
1 parent 45dfc4b commit 011e42d

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# User Impersonation Activity Logger
2+
3+
A ServiceNow server-side utility that automatically creates a log when an action is performed under impersonation, helping distinguish between admin-added and user-added notes.
4+
5+
# Challenge
6+
7+
The challenge lies in distinguishing between actions performed by administrators impersonating users and those performed by the users themselves. Without a reliable way to track impersonation activity, it becomes difficult to ensure transparency and accountability in ticket histories. This lack of clarity can lead to confusion during audits, misinterpretation of updates, and potential compliance risks. Addressing this issue is critical to maintaining trust and operational efficiency.
8+
9+
## Description
10+
11+
This script identifies if the current user session is under impersonation (e.g., an admin impersonating another user).
12+
If true, it automatically appends a message in the **Logs** indicating that the note was added during impersonation.
13+
This improves auditability and clarity when reviewing ticket histories.
14+
15+
## Functionality
16+
17+
The User Impersonation Activity Logger provides the following capabilities:
18+
- Detects if the current user is impersonating another user
19+
- Automatically appends a log message stating the impersonation context
20+
- Works in **Business Rule** and Global Scoped Tables
21+
- Logs both actual user and impersonated user details
22+
- Provides clear distinction for audit and tracking
23+
24+
## Usage Instructions
25+
26+
### Add as Business Rule
27+
28+
```javascript
29+
// When: before update
30+
// Table: incident
31+
// Script:
32+
(function executeRule(current, previous /*null when async*/) {
33+
34+
//Add the logic here
35+
36+
})(current, previous);
37+
```
38+
39+
40+
## Prerequisites
41+
42+
- Need admin access to check the impersonation logs later
43+
44+
45+
## Dependencies
46+
47+
- GlideSystem API
48+
- GlideImpersonate API
49+
- gs.getSession()
50+
51+
52+
## Category
53+
54+
Server-Side Components / Business Rules / User Impersonation Activity Logger
55+
56+
57+
## Screenshots
58+
<img width="3024" height="536" alt="image" src="https://github.com/user-attachments/assets/3ae408db-175f-4281-a9d7-f21df16314e7" />
59+
60+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(function executeRule(current, previous /*null when async*/) {
2+
if (new GlideImpersonate().isImpersonating()) {
3+
// Check if the user is impersonating
4+
if (current.comments.changes() || current.work_notes.changes()) {
5+
// Check if comments or work notes have changed
6+
let actualUserName = gs.getImpersonatingUserDisplayName();
7+
let impersonatedUserName = gs.getUserDisplayName();
8+
let logMessage = `User Impersonation Activity Detected:
9+
Timestamp : ${new GlideDateTime()}
10+
Actual User: ${actualUserName}
11+
Impersonated User: ${impersonatedUserName}
12+
Comments added: ${current.comments || "NA"}
13+
Work Notes added: ${current.work_notes || "NA"}`;
14+
gs.info(logMessage);
15+
}
16+
}
17+
})(current, previous);

0 commit comments

Comments
 (0)