Send notification prior to 90,60 and 30days of a date selected on a variable in a catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2024 07:11 PM
Hi all,
I have a a field on a catalog item called risk ending date(It can be either date or date/time type). I need to send an email notification before 90th,60th and 30th days of it's ending date. I used this script in the timer activity but the timer starts and ends immediately(within fraction of seconds) . Please help me with to set the timer to trigger when left with 30days to the risk ending date. TIA.
var gdt = new GlideDateTime(current.variables.risk_ending_date);
gdt.addDays(-30);
answer = gs.dateDiff(gs.nowDateTime(), gdt, true);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2024 10:46 PM
Move away from the workflow and create a flow through flow designer. You can just configure your wait conditions in there.
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
‎07-23-2024 11:07 PM
Hello @Sona2 ,
To achieve the desired notification timing in ServiceNow, you can use scheduled jobs or scheduled notifications instead of a timer activity, which is not designed for long-term scheduling. Here's how you can set up scheduled notifications for 90, 60, and 30 days before the risk_ending_date:
Create Scheduled Notifications:
- Notification for 90 Days Before:
- Create a scheduled notification with a condition that triggers 90 days before the risk_ending_date.
- Notification for 60 Days Before:
- Create another scheduled notification for 60 days before the risk_ending_date.
- Notification for 30 Days Before:
- Create the final scheduled notification for 30 days before the risk_ending_date.
- Notification for 90 Days Before:
Scheduled Script Execution: You can use a Scheduled Script Execution to calculate the days remaining until the risk_ending_date and send notifications accordingly.
Here's an example of a scheduled script that you can use:
var gr = new GlideRecord('sc_req_item'); // Change to your catalog item table if different
gr.addNotNullQuery('risk_ending_date');
gr.query();
while (gr.next()) {
var riskEndingDate = new GlideDateTime(gr.getValue('risk_ending_date'));
var now = new GlideDateTime();
var diff = gs.dateDiff(now.getDisplayValue(), riskEndingDate.getDisplayValue(), true);
if (diff <= 90 && diff > 89) {
// Send email for 90 days
gs.eventQueue('risk.notification.90days', gr, gr.sys_id, gr.request.requested_for);
}
if (diff <= 60 && diff > 59) {
// Send email for 60 days
gs.eventQueue('risk.notification.60days', gr, gr.sys_id, gr.request.requested_for);
}
if (diff <= 30 && diff > 29) {
// Send email for 30 days
gs.eventQueue('risk.notification.30days', gr, gr.sys_id, gr.request.requested_for);
}
}
- Event Registration:
- Register the events risk.notification.90days, risk.notification.60days, and risk.notification.30days in the Event Registry.
- Create email notifications linked to these events.
Thank you!!
Dnyaneshwaree Satpute
Tera Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2024 11:15 PM
If you are going to share AI generated answers, please validate them before sharing. The date difference will be calculated in milli seconds, how is this ever going to work?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark