Email Wishes Autogenerated for sys_users.

Abbas_Ahamed
Tera Contributor

Hi Team,

 

           I have a doubt in autogenerated email wishes for DOB sys_user tables. I don't need the year of every user only calculating the date and month. For example sys_user DOB has 03/07 and it's take current date of 03/07 like this. So, I already tried some code but it's not working. I ping the code below for your reference. Can anyone kindly help me solve the issue. 

 

Ref Code:

 

I have done this code on scheduled jobs.

 

// Scheduled Script to send birthday emails
var today = new GlideDate();
today.setDisplayValue(gs.nowDateTime());

var users = new GlideRecord('sys_user');
users.addQuery('birthday', today); // replace birthday with DOB field
users.query();

while (users.next()) {
var recipientName = users.getValue('name');
var recipientEmail = users.getValue('email');

var emailTemplateSysId = 'ENTER_YOUR_EMAIL_TEMPLATE_SYS_ID'; // Replace with the sys_id of the email template you created Or use Email script instead

// Send the email
var email = GlideEmailOutbound.init(emailTemplateSysId);
email.setSubject('Happy Birthday, ' + recipientName + '!');
email.addRecipient(recipientEmail);
email.send();
}

 

 

 

Thanks,

Allen_001

1 REPLY 1

Azem
Tera Guru

Hi Allen - hope all is well.

 

If the value of the birthday field follows the format provided (e.g., 03/07), try the below script instead.

 

 

 

//Format date
var today = new GlideDate();
var format = today.getByFormat('MM/dd');

//Get users
var users = new GlideRecord('sys_user');
users.addQuery('birthday', format); // replace birthday with DOB field
users.query();

while (users.next()) {
var recipientName = users.getValue('name');
var recipientEmail = users.getValue('email');

var emailTemplateSysId = 'ENTER_YOUR_EMAIL_TEMPLATE_SYS_ID'; // Replace with the sys_id of the email template you created Or use Email script instead

// Send the email
var email = GlideEmailOutbound.init(emailTemplateSysId);
email.setSubject('Happy Birthday, ' + recipientName + '!');
email.addRecipient(recipientEmail);
email.send();
}

 

 

 

Reference: https://developer.servicenow.com/dev.do#!/reference/api/utah/server/no-namespace/c_GlideDateScopedAP...