Skip to content

Commit e33c87f

Browse files
authored
User Email mismatch with Cmn_notif_device email - finder (#2668)
1 parent 142cd6b commit e33c87f

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Email Mismatch Checker
2+
3+
## Description
4+
5+
This ServiceNow background script checks for mismatches between notification devices and user records based on email addresses.
6+
7+
It looks for active `cmn_notif_device` records that:
8+
- Have a non-null `email_address`
9+
- Are linked to a user
10+
- Are of type "Email"
11+
- Are named "Primary Email"
12+
13+
Then it verifies if a matching user exists in the `sys_user` table with the same email. If no match is found, the mismatch is logged.
14+
15+
## How to Use
16+
17+
1. Go to **Scripts > Background** in your ServiceNow instance.
18+
2. Paste the script.
19+
3. Run the script.
20+
4. Check the system logs for mismatch details.
21+
22+
## Output
23+
24+
Logs the number of mismatches and details like:
25+
Mismatch: Device=<device_name>, Device Email=<email_address>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Background Script - Run in Scripts > Background
2+
3+
function findEmailMismatches() {
4+
var mismatches = [];
5+
6+
var deviceGR = new GlideRecord('cmn_notif_device');
7+
deviceGR.addNotNullQuery('email_address'); // Only check devices with email populated
8+
deviceGR.addNotNullQuery("user"); // Ensure device is linked to a user
9+
deviceGR.addQuery("type", "Email"); // Filter for email-type devices
10+
deviceGR.addQuery("name", "Primary Email");// Filter for primary email devices
11+
deviceGR.addActiveQuery(); // Only active devices
12+
deviceGR.query();
13+
14+
while (deviceGR.next()) {
15+
var userGR = new GlideRecord('sys_user');
16+
userGR.addQuery('email', deviceGR.email_address);
17+
userGR.query();
18+
19+
if (!userGR.next()) {
20+
// Found a mismatch
21+
mismatches.push({
22+
device_sys_id: deviceGR.getUniqueValue(),
23+
device_name: deviceGR.getDisplayValue(),
24+
email: deviceGR.email_address.toString(),
25+
user_sys_id: 'No matching user found'
26+
});
27+
}
28+
}
29+
30+
return mismatches;
31+
}
32+
33+
// Execute and log results
34+
var results = findEmailMismatches();
35+
gs.info('Found ' + results.length + ' email mismatches:');
36+
37+
for (var i = 0; i < results.length; i++) {
38+
gs.info('Mismatch: Device=' + results[i].device_name + ', Device Email=' + results[i].email);
39+
}

0 commit comments

Comments
 (0)