trigger an email for birthday from the table by comparing dob field with current day and month

Varma0326
Tera Contributor

We need to trigger an Email notification for Birthday for the user from the 'sys_user' Table . We need to compare only day and month of the dob field and comparing with current day and month and email need to send for that user's email id. help me with the complete process and code.

2 REPLIES 2

Samaksh Wani
Giga Sage
Giga Sage

Hello @Varma0326 

 

You can create a Occasion and Link it with Notification :-

 

Plz go through the below link :-

https://developer.servicenow.com/print_page.do?release=tokyo&category=course-module&identifier=app_s...

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh

Amit Gujarathi
Giga Sage
Giga Sage

HI @Varma0326 ,
I trust you are doing great,
Please find the below script for the same

// Get the current date and month in the format '00-MM-DD'
var currentMonthDay = '00-' + (new GlideDate().getMonthDay());

// Query the sys_user table for users with matching birthday
var userGR = new GlideRecord('sys_user');
userGR.addQuery('dob', 'LIKE', currentMonthDay);
userGR.query();

// Loop through the users and send the birthday notifications
while (userGR.next()) {
    var recipientEmail = userGR.email.getDisplayValue();
    var emailTemplate = 'TEMPLATE_NAME'; // Replace 'TEMPLATE_NAME' with the name of your created email template
    gs.eventQueue('birthday.notification', userGR, emailTemplate, recipientEmail);
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi