Hi I need to map email address of user record with the related list of AD account email address

ServiceNow10sun
Giga Guru

Hi,

 

I need a compare the user email address in user record with the Ad account email address which is in the related list for user record ,

 

how can i compare this email address and if there is a difference in the email address i need to send an daily to a particular group

 

how can i achieve this any suggestion

thanks

 

 

 

10 REPLIES 10

Hi Saurabh,

// Create a new GlideRecord for sys_user table with an encoded query
var sysUser = new GlideRecord('sys_user');
sysUser.addEncodedQuery('u_account_typeINemployee,contractor^active=true^email_addressLIKEbhn.com,LIKEbhnetwork.com');
sysUser.query();

var matchFound = false; // Initialize the matchFound flag to false

while (sysUser.next()) {
var sysUserEmail = sysUser.email.toString();

// Create a new GlideRecord for u_ad_user_account table with an encoded query
var adUser = new GlideRecord('u_ad_user_account');
adUser.addEncodedQuery('email_address=' + sysUserEmail);
adUser.query();

if (adUser.next()) {
// A match is found, set matchFound to true and break out of the loop
matchFound = true;
break;
}
}

// Send an email outside the loop if no match is found
if (!matchFound) {
var email = new GlideEmailOutbound();
email.setSubject('No Email Match Found');
email.setBody('No matching email addresses found.');
email.addRecipient('group@example.com'); // Add recipient group email address
email.send();
}

 

am using the script but still when i check the logs am not able to see any emails.

could you please suggest if there is any issue with this script

thanks