Trigger Notification before 60 days based on specific field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 02:48 AM
Hello All,
I got an requirment that we need to trigger notification before 60 days of the contract expiry date (Date field).
Can anyone help me how to configure this requirment.
Regards,
Hemanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 03:02 AM
Hi,
It is advisable to utilize a scheduled job, as this will facilitate the specification of the time frequency. Furthermore, consider using a field or flag from the table to establish the trigger condition. Additionally, prepare a notification template and invoke it through the use of a script.
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 03:13 AM
Hello ersureshbe,
i have tried the scheduled job but the notification is not triggering
var gr = new GlideRecord('ast_contract');
gr.addQuery('active', true);
gr.query();
while(gr.next()){
var todayDate = new GlideDateTime();
var expiry = new GlideDateTime(gr.getValue('ends'));
var duration = gs.dateDiff(todayDate.getDisplayValue(),expiry.getDisplayValue()t, true);
if(days==60){
gs.eventQueue('sn_pr.expiry.notification', gr , gr.sys_id, null);
}
}
please correct my code if i have gone wrong
Regards,
Hemanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 03:36 AM
Hello @vivek110 ,
PLease give a try to the script below and see how it works for you!!!
// Query the 'ast_contract' table for active contracts
var gr = new GlideRecord('ast_contract');
gr.addQuery('active', true); // Only process active contracts
gr.query();
while (gr.next()) {
// Get today's date
var todayDate = new GlideDateTime();
// Get the contract's expiry date
var expiry = new GlideDateTime(gr.getValue('ends'));
// Calculate the difference in milliseconds
var duration = gs.dateDiff(todayDate.getDisplayValue(), expiry.getDisplayValue(), true);
// Convert the difference from milliseconds to days
var daysDifference = parseInt(duration) / (1000 * 60 * 60 * 24);
// Trigger notification if there are exactly 60 days left until expiry
if (daysDifference === 60) {
gs.eventQueue('sn_pr.expiry.notification', gr, gr.sys_id, null); // Queue the notification event
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 04:50 AM