- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 02:12 PM
Hi ,
I am trying to configure email which will be sent to users when they complete 6 months+ 2days at the organization. For example, We have the Hire Date in the HR Profiles table, If the value of this field is 2024-01-20 then an email should be sent on 2024-07-22. How can I achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 10:05 PM
You could use a daily scheduled job to run a script like below. Please review the fields and tables, because with lacking that information in your question, it's assumptions. If your hire date isn't a date/time field, you will need to adjust.
If you have the notification in the system, you can also leave out the creating of the email and just trigger it through an event. But the script is a basis to start from.
(function() {
var hrProfileGR = new GlideRecord('hr_profile');
hrProfileGR.addQuery('active', true);
hrProfileGR.query();
while (hrProfileGR.next()) {
var hireDate = new GlideDateTime(hrProfileGR.getValue('hire_date'));
var today = new GlideDateTime();
var sixMonthsPlusTwoDays = new GlideDateTime(hireDate);
sixMonthsPlusTwoDays.addMonthsUTC(6);
sixMonthsPlusTwoDays.addDaysUTC(2);
if (sixMonthsPlusTwoDays.equals(today)) {
// Send email
var emailParams = {
subject: "Congratulations on your milestone!",
body: "Dear " + hrProfileGR.getValue('name') + ",\n\nCongratulations on completing 6 months and 2 days at our organization!\n\nBest Regards,\nHR Team",
recipient: hrProfileGR.getValue('email')
};
sendEmail(emailParams);
}
}
function sendEmail(params) {
var gr = new GlideRecord('sys_email');
gr.initialize();
gr.type = 'send-ready';
gr.subject = params.subject;
gr.recipients = params.recipient;
gr.body = params.body;
gr.insert();
}
})();
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 10:05 PM
You could use a daily scheduled job to run a script like below. Please review the fields and tables, because with lacking that information in your question, it's assumptions. If your hire date isn't a date/time field, you will need to adjust.
If you have the notification in the system, you can also leave out the creating of the email and just trigger it through an event. But the script is a basis to start from.
(function() {
var hrProfileGR = new GlideRecord('hr_profile');
hrProfileGR.addQuery('active', true);
hrProfileGR.query();
while (hrProfileGR.next()) {
var hireDate = new GlideDateTime(hrProfileGR.getValue('hire_date'));
var today = new GlideDateTime();
var sixMonthsPlusTwoDays = new GlideDateTime(hireDate);
sixMonthsPlusTwoDays.addMonthsUTC(6);
sixMonthsPlusTwoDays.addDaysUTC(2);
if (sixMonthsPlusTwoDays.equals(today)) {
// Send email
var emailParams = {
subject: "Congratulations on your milestone!",
body: "Dear " + hrProfileGR.getValue('name') + ",\n\nCongratulations on completing 6 months and 2 days at our organization!\n\nBest Regards,\nHR Team",
recipient: hrProfileGR.getValue('email')
};
sendEmail(emailParams);
}
}
function sendEmail(params) {
var gr = new GlideRecord('sys_email');
gr.initialize();
gr.type = 'send-ready';
gr.subject = params.subject;
gr.recipients = params.recipient;
gr.body = params.body;
gr.insert();
}
})();
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 06:58 AM
Thank you so much Mark. The script you shared give me a good start. The Hire Date field is "GlideDate". Could you please suggest the modification required on the script.