Skip to content

Commit 71fe743

Browse files
authored
Create userEmailMismatchwithcmnNotifDevice.js
Script to find the User email mismatch with Cmn_notif_device email to detect and eliminate the notification failures
1 parent 142cd6b commit 71fe743

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
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)