From 71fe7439c92d18c028c3682f6f1e797c9526c0ec Mon Sep 17 00:00:00 2001 From: Vasantharajan N <51485948+nvprav@users.noreply.github.com> Date: Sat, 1 Nov 2025 01:20:41 +0530 Subject: [PATCH 1/2] Create userEmailMismatchwithcmnNotifDevice.js Script to find the User email mismatch with Cmn_notif_device email to detect and eliminate the notification failures --- .../userEmailMismatchwithcmnNotifDevice.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Server-Side Components/Background Scripts/User Email mismatch with Cmn Notif device/userEmailMismatchwithcmnNotifDevice.js diff --git a/Server-Side Components/Background Scripts/User Email mismatch with Cmn Notif device/userEmailMismatchwithcmnNotifDevice.js b/Server-Side Components/Background Scripts/User Email mismatch with Cmn Notif device/userEmailMismatchwithcmnNotifDevice.js new file mode 100644 index 0000000000..29861cd085 --- /dev/null +++ b/Server-Side Components/Background Scripts/User Email mismatch with Cmn Notif device/userEmailMismatchwithcmnNotifDevice.js @@ -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); +} From 7b25f954823830bf5546079352847e0405f17ee4 Mon Sep 17 00:00:00 2001 From: Vasantharajan N <51485948+nvprav@users.noreply.github.com> Date: Sat, 1 Nov 2025 01:21:42 +0530 Subject: [PATCH 2/2] Add README.md Instructions about the overview of the script --- .../README.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Server-Side Components/Background Scripts/User Email mismatch with Cmn Notif device/README.md diff --git a/Server-Side Components/Background Scripts/User Email mismatch with Cmn Notif device/README.md b/Server-Side Components/Background Scripts/User Email mismatch with Cmn Notif device/README.md new file mode 100644 index 0000000000..e65c44f3d2 --- /dev/null +++ b/Server-Side Components/Background Scripts/User Email mismatch with Cmn Notif device/README.md @@ -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 Email=