-
Notifications
You must be signed in to change notification settings - Fork 858
User impersonation activity logger #2401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ravichandra1998g
merged 7 commits into
ServiceNowDevProgram:main
from
Its-Nmk:user-impersonation-activity-logger
Oct 22, 2025
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f9ccfa5
Create README for User Impersonation Activity Logger
Its-Nmk fb4756e
Add user impersonation activity logging
Its-Nmk e85e26f
Add screenshot to README for User Impersonation Logger
Its-Nmk 7186965
Merge branch 'ServiceNowDevProgram:main' into user-impersonation-acti…
Its-Nmk cd2c541
Update README by removing unnecessary sections
Its-Nmk 5056cb6
Merge branch 'ServiceNowDevProgram:main' into user-impersonation-acti…
Its-Nmk 6ec903f
Remove user impersonation activity logging
Its-Nmk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
Server-Side Components/Business Rules/User Impersonation Activity Logger/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# User Impersonation Activity Logger | ||
|
||
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. | ||
|
||
# Challenge | ||
|
||
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. | ||
|
||
## Description | ||
|
||
This script identifies if the current user session is under impersonation (e.g., an admin impersonating another user). | ||
If true, it automatically appends a message in the **Logs** indicating that the note was added during impersonation. | ||
This improves auditability and clarity when reviewing ticket histories. | ||
|
||
## Functionality | ||
|
||
The User Impersonation Activity Logger provides the following capabilities: | ||
- Detects if the current user is impersonating another user | ||
- Automatically appends a log message stating the impersonation context | ||
- Works in **Business Rule** and Global Scoped Tables | ||
- Logs both actual user and impersonated user details | ||
- Provides clear distinction for audit and tracking | ||
|
||
## Usage Instructions | ||
|
||
### Add as Business Rule | ||
|
||
```javascript | ||
// When: before update | ||
// Table: incident | ||
// Script: | ||
(function executeRule(current, previous /*null when async*/) { | ||
if (new GlideImpersonate().isImpersonating()) { // Check if the user is impersonating | ||
if (current.comments.changes() || current.work_notes.changes()) { // Check if comments or work notes have changed | ||
let actualUserName = gs.getImpersonatingUserDisplayName(); | ||
let impersonatedUserName = gs.getUserDisplayName(); | ||
let logMessage = `User Impersonation Activity Detected: | ||
Timestamp : ${ new GlideDateTime()} | ||
Actual User: ${actualUserName} | ||
Impersonated User: ${impersonatedUserName} | ||
Comments added: ${current.comments || 'NA'} | ||
Work Notes added: ${current.work_notes || 'NA'}`; | ||
gs.info(logMessage); | ||
} | ||
} | ||
})(current, previous); | ||
``` | ||
|
||
|
||
## Prerequisites | ||
|
||
- Need admin access to check the impersonation logs later | ||
|
||
|
||
## Dependencies | ||
|
||
- GlideSystem API | ||
- GlideImpersonate API | ||
- gs.getSession() | ||
|
||
|
||
## Category | ||
|
||
Server-Side Components / Business Rules / User Impersonation Activity Logger | ||
|
||
## Hacktoberfest 2025 | ||
|
||
Created as first Contribution for ServiceNow Hacktoberfest 2025 🎃 | ||
|
||
## License | ||
|
||
MIT License | ||
Its-Nmk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Screenshots | ||
<img width="3024" height="536" alt="image" src="https://github.com/user-attachments/assets/3ae408db-175f-4281-a9d7-f21df16314e7" /> | ||
|
||
|
17 changes: 17 additions & 0 deletions
17
...nents/Business Rules/User Impersonation Activity Logger/UserImpersonationActiityLogger.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(function executeRule(current, previous /*null when async*/) { | ||
if (new GlideImpersonate().isImpersonating()) { | ||
// Check if the user is impersonating | ||
if (current.comments.changes() || current.work_notes.changes()) { | ||
// Check if comments or work notes have changed | ||
let actualUserName = gs.getImpersonatingUserDisplayName(); | ||
let impersonatedUserName = gs.getUserDisplayName(); | ||
let logMessage = `User Impersonation Activity Detected: | ||
Timestamp : ${new GlideDateTime()} | ||
Actual User: ${actualUserName} | ||
Impersonated User: ${impersonatedUserName} | ||
Comments added: ${current.comments || "NA"} | ||
Work Notes added: ${current.work_notes || "NA"}`; | ||
gs.info(logMessage); | ||
} | ||
} | ||
})(current, previous); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not need to add the script again in a Readme file.
Can you please remove this part too...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ravichandra1998g - I have removed the code but just having a placeholder for script to highlight that we need to add a code in BR.