Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Email Mismatch Checker

## Description

This ServiceNow background script checks for mismatches between notification devices and user records based on email addresses.

It looks for active `cmn_notif_device` records that:
- Have a non-null `email_address`
- Are linked to a user
- Are of type "Email"
- Are named "Primary Email"

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.

## How to Use

1. Go to **Scripts > Background** in your ServiceNow instance.
2. Paste the script.
3. Run the script.
4. Check the system logs for mismatch details.

## Output

Logs the number of mismatches and details like:
Mismatch: Device=<device_name>, Device Email=<email_address>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Background Script - Run in Scripts > Background

function findEmailMismatches() {
var mismatches = [];

var deviceGR = new GlideRecord('cmn_notif_device');
deviceGR.addNotNullQuery('email_address'); // Only check devices with email populated
deviceGR.addNotNullQuery("user"); // Ensure device is linked to a user
deviceGR.addQuery("type", "Email"); // Filter for email-type devices
deviceGR.addQuery("name", "Primary Email");// Filter for primary email devices
deviceGR.addActiveQuery(); // Only active devices
deviceGR.query();

while (deviceGR.next()) {
var userGR = new GlideRecord('sys_user');
userGR.addQuery('email', deviceGR.email_address);
userGR.query();

if (!userGR.next()) {
// Found a mismatch
mismatches.push({
device_sys_id: deviceGR.getUniqueValue(),
device_name: deviceGR.getDisplayValue(),
email: deviceGR.email_address.toString(),
user_sys_id: 'No matching user found'
});
}
}

return mismatches;
}

// Execute and log results
var results = findEmailMismatches();
gs.info('Found ' + results.length + ' email mismatches:');

for (var i = 0; i < results.length; i++) {
gs.info('Mismatch: Device=' + results[i].device_name + ', Device Email=' + results[i].email);
}
Loading