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,

 

Any suggestion on this 

 

thanks

Hi,
When you want to check these mismatches, meaning you want once in a day job to check if email in both tables is same if not then there should be an email to a particular group?

 

 


Thanks and Regards,

Saurabh Gupta

Hi Saurabh, 

 

yes i need a daily job to send email to particular group if there is a mismatch in email address yes correct

thanks

 

Hi,
You can write a scheduled job and check if there is a mismatch then using events trigger the notification.

How to check mismatch, I would suggest creating a reference field on your custom table referencing sys_user, it will help to find mismatch.

 

 


Thanks and Regards,

Saurabh Gupta

Hi Saurabh, 

 

Below is the script which i am using to compare the email addresses available in customized table ' u_ad_accounts'   which is in related list   of user table as well ( provided the screen shot).

In sys_user table and in u_ad_accounts table the common  field is 'employee number' field in sys_user and in u_ad_accounts table there is EMP id field based on which i have build the below script , however my actual requirement is  on a weekly basis a notification should trigger to ServiceNow support team group with u_ad_accounts table email address which are mismatched with the sys_user table email address example  in notification we can give  "  Employee number 12345   has email ids  XYZ@gmail.com , XYZ1@gmail.com in AD account table and in sys_user table the email id is XYZright@gmail.com."

 

For testing purpose i have created a field u_ad_account_status in sys_user table  and update comments like if email ids are same then update comments as email id are matching else  update all email ids .  the below script is working , however for notification to trigger with the above requirement is not working.

 

Please suggest . Thank you in Advance.

var userGr = new GlideRecord('sys_user');
userGr.query();

while (userGr.next()) {

    if (userGr.employee_number) {
        // Query the u_ad_account table for matching records

        var adAccountGr = new GlideRecord('u_ad_accounts');

        adAccountGr.addQuery('u_emp_id', userGr.employee_number);

        adAccountGr.query();

        var emailMismatch = 1;
        var emailAddresses = [];

        // Iterate through the matching ad_account records

        while (adAccountGr.next()) 
		{
           
            if (userGr.email != adAccountGr.u_email)                             // Check if email id and email address match
			
			{
                ++emailMismatch;
            }

            emailAddresses.push(adAccountGr.u_email);
        }
        
        if (emailMismatch > 1)                                       // Update the u_ad_account_status field in the sys_user record
		{
            userGr.u_ad_account_status = emailAddresses.join(', ');


        } else {
			
            userGr.u_ad_account_status = "all emails match";
        }

        // Update the sys_user record
        userGr.update();
    }
}