- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 11:59 PM
I trying to dynamically change the content & subject of the reminder email notifications based on conditions like 1 week, 2weeks, final reminder etc rather than using multiple notifciations?
Can we achieve this using a single notification and by using a mail script?
TIA
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 01:05 AM
Hi @Raviteja Kunal1 ,
Yes, you can achieve this by using a single notification and customising the email content and subject dynamically based on your conditions using a mail script. Here's an example of how you can do this:
Create a single notification record with a default email body and subject that will be used if none of the conditions are met.
Write a mail script that checks the conditions you want to use to dynamically change the email content and subject. For example, you could use the current date and time to check if the reminder is for 1 week, 2 weeks, or the final reminder.
In the mail script, use the email.setSubject() and email.setBody() methods to dynamically set the email subject and body based on your conditions.
Call the mail script from your reminder script to send the email notification.
Here's an example code snippet:
var now = new GlideDateTime();
var reminderDate = new GlideDateTime();
reminderDate.addWeeks(1);
// Check if this is the 1 week reminder
if (now.equals(reminderDate)) {
// Set the email subject and body for the 1 week reminder
email.setSubject("1 Week Reminder: Your Task is Due Soon");
email.setBody("Hello,\n\nThis is a reminder that your task is due in 1 week. Please complete it as soon as possible.\n\nThank you.");
}
// Check if this is the 2 week reminder
else if (now.equals(reminderDate.addWeeks(1))) {
// Set the email subject and body for the 2 week reminder
email.setSubject("2 Week Reminder: Your Task is Due Soon");
email.setBody("Hello,\n\nThis is a reminder that your task is due in 2 weeks. Please complete it as soon as possible.\n\nThank you.");
}
// Check if this is the final reminder
else if (now.equals(reminderDate.addWeeks(1))) {
// Set the email subject and body for the final reminder
email.setSubject("Final Reminder: Your Task is Overdue");
email.setBody("Hello,\n\nThis is a final reminder that your task is overdue. Please complete it as soon as possible.\n\nThank you.");
}
// If none of the conditions are met, use the default email subject and body
else {
email.setSubject(gs.getMessage("Task Reminder"));
email.setBody(gs.getMessage("This is a reminder that you have a task that is due soon."));
}
// Send the email notification
email.send();
you can also refer - Scripting examples for email notifications
If my response helps you to resolve the issue close the question by ✅Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 01:38 AM
Hi @Raviteja Kunal1 ,
Please find below code for weekly reminder:
// Check if today is Thursday
var today = new Date();
if (today.getDay() === 4) { // Thursday is 4th day of the week
emailSubject = 'Weekly Reminder';
emailBody = 'This is your weekly reminder email.';
}
And, for 3 days:
var today = new Date();
var deadline = new Date('2023-03-20'); // Replace with your actual deadline date
var threeDaysBeforeDeadline = new Date(deadline.getTime() - 3 * 24 * 60 * 60 * 1000); // Calculate 3 days before deadline
if (today.getTime() === threeDaysBeforeDeadline.getTime()) {
emailSubject = 'Reminder: Deadline in 3 days';
emailBody = 'This is a reminder that your deadline is in 3 days.';
}
Thanks,
Ratnakar