How to add attachement in the notification

siddharth26
Tera Guru

Hi All,

i have created a email script which triggers the email with difference in the email address in user table and AD user table , so am getting the result in the notification email , but i need these details in the excel format, how can i get these details in the excel format in the notification.

 

this is the email script

var mism = []; // Define the array to store mismatched employee numbers

var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery('active=true^u_account_typeINemployee,contractor');
userGr.query();

while (userGr.next()) {
if (userGr.u_number) {
var adAccountGr = new GlideRecord('u_ad_user_account');
adAccountGr.addEncodedQuery('u_active=true^u_employeenumberISNOTEMPTY');
adAccountGr.addQuery('u_employeenumber', userGr.u_number);
adAccountGr.query();

var emailMismatch = false; // Initialize emailMismatch to false

while (adAccountGr.next()) {

var userPrefix = userGr.email.getDisplayValue().split('@')[0];
var adPrefix = adAccountGr.u_mail.getDisplayValue().split('@')[0];
// Check for email mismatches
if (!(adAccountGr.u_mail.contains("vyx.com") || adAccountGr.u_mail.contains("abc.com"))||(userPrefix!==adPrefix))

{
emailMismatch = true;
break; // Exit the loop if a mismatch is found for this user
}
}

if (emailMismatch) {
mism.push(userGr.u_number.toString());
}
}
}

if (mism.length > 0) {
template.print("The Employee numbers of users whose email IDs are mismatched: " + mism.join(', ') + "\n");
}

})(current, template, email, email_action, event);

 

email notification am getting as below:

siddharth26_0-1695881738890.png

but i need these details in the excel format in the email notification.

 

any suggestion.

 

thank

1 REPLY 1

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please check the below post and response from the Servicenow employee:-

 

https://www.servicenow.com/community/itsm-forum/how-to-generate-excel-file-from-a-script-in-servicen...

 

Please mark my answer as correct based on Impact.