Need to compare email address from user table to email address in ad account table and send notiy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 12:20 AM
Hi All,
Am using below script to match the email address from user table to email address i AD table and if mismatch is found in email address i need a email to be sent out with the details.
/
/ 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^);
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();
}
but am not getting any emails when mismatch is found could you please suggest .
thanks
sid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 12:27 AM
Hi @siddharth26 ,
Check line sysUser.addEncodedQuery('u_account_typeINemployee,contractor^active=true^);
It should be sysUser.addEncodedQuery('u_account_typeINemployee,contractor^active=true^');
You missed to complete single quote.
Please check and Mark Helpful and Correct if it really helps you.
Regards,
Mayur Shardul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 12:33 AM
Hi Mayur,
thanks for the reply
var sysUser = new GlideRecord('sys_user');
sysUser.addEncodedQuery('u_account_typeINemployee,contractor^active=true');
sysUser.query();
var matchFound = false;
while (sysUser.next()) {
var sysUserEmail = sysUser.email.toString();
if (sysUserEmail.endsWith('xyz.') || sysUserEmail.endsWith('abc.com')) {
var adUser = new GlideRecord('u_ad_user_account');
adUser.addQuery('email_address', sysUserEmail);
adUser.query();
if (adUser.next()) {
matchFound = true;
break;
}
}
}
if (!matchFound) {
var email = new GlideEmailOutbound();
email.setSubject('No Email Match Found');
email.setBody('No matching email addresses found.');
email.addRecipient('siddharth@example.com');
email.send();
}
i have made the changes to the query as well but still we the emails are not been sent .
could you please suggest
thanks