Passing Age onto and email Template

Rodzula
Tera Contributor

Hi

How would one pass the Age of someone's birthday onto an email template or email notification,
Having created a scheduled job with this script.

var currentdate = new GlideDate();
var today = new Date(); // Get the current date as a JavaScript Date object

gs.info(currentdate.getDisplayValue().substring(5));
var profile = new GlideRecord('sn_hr_core_profile');

profile.query();

while (profile.next()) {
var user_birthday = profile.getValue("date_of_birth"); // date of birth
var user_company = profile.user.company.getDisplayValue(); // user company

var bday = user_birthday.substring(5);
var tday = currentdate.getDisplayValue().substring(5);

if (user_company == "example" && bday == tday) {
// Calculate the age
var birthDate = new Date(user_birthday); // Convert user's date of birth to a JavaScript Date object
var age = today.getFullYear() - birthDate.getFullYear();

// Trigger the email script with the necessary information
gs.eventQueue("sn_hr_core", profile, profile.user.email, age);
}
}

Thanks

0 REPLIES 0