- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2024 04:40 AM - edited ‎10-09-2024 05:19 AM
Hi team,
I have requirement to send notification one day before and one day after a variable date field in catalog item. I used scheduled job,event and notification for that...but when its running daily its sending notification everyday and it seems not working....like if i keep date as 9oct in date field in catalog form so one noti should be send on 8 and one on 10th but it seems not working can anyone please help me attaching schedule job script here:- @Sandeep Rajput @Dr Atul G- LNG
Before:-
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2024 02:08 AM
Hello Priyanka,
Can you try this below,
I have executed this in background script, also I see that this is a date/time field so getDisplayValue will not work properly, just getDate should do that job.
var catalogItemSysId = '6830ece6937056109458f44e1dba10ee';
var variableDateField = 'expected_return_date';
var grBefore = new GlideRecord('sc_req_item');
grBefore.addQuery('cat_item', catalogItemSysId);
grBefore.query();
while (grBefore.next()) {
var dt = grBefore.variables[variableDateField];
if (dt) {
var expectedDate = new GlideDateTime(dt);
gs.info('expectedDate' +expectedDate);
var today =new GlideDateTime();
var oneDayBefore = new GlideDateTime(dt);
oneDayBefore.addDays(-1);
gs.info('today' +today);
if (today.getDate().getNumericValue() == oneDayBefore.getDate().getNumericValue()) {
{
gs.eventQueue('loaner.request.one.day.before', grBefore, grBefore.requested_for, '');
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2024 11:54 PM
Hey @Omkar Mukesh Mo again both notifications are getting triggered if i keep my expected_return_date as 11 and fill the form and submit i kept both schedule job to run periodically 1 min to check...so both notifications coming....after noti should be triggred on 12 not today

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2024 11:57 PM
Hello
I see, then you need to create new fields in order to keep a track.
notification_sent_before and notification_sent_after to determine if a notification has already been sent for the given record.
var catalogItemSysId = '6830ece6937056109458f44e1dba10ee';
var variableDateField = 'u_variable_date_field';
var grBefore = new GlideRecord('sc_req_item');
grBefore.addQuery('cat_item', catalogItemSysId);
grBefore.addQuery(variableDateField, '=', gs.daysAgoStart(1));
grBefore.addQuery('notification_sent_before', '!=', true); // Check if notification already sent
grBefore.query();
while (grBefore.next()) {
gs.eventQueue('event.before', grBefore, grBefore.requested_for, '');
grBefore.notification_sent_before = true; // Set a flag to indicate notification was sent
grBefore.update(); // Update the record to save the flag
}
var grAfter = new GlideRecord('sc_req_item');
grAfter.addQuery('cat_item', catalogItemSysId);
grAfter.addQuery(variableDateField, '=', gs.daysAheadStart(1));
grAfter.addQuery('notification_sent_after', '!=', true); // Check if notification already sent
grAfter.query();
while (grAfter.next()) {
gs.eventQueue('event.after', grAfter, grAfter.requested_for, '');
grAfter.notification_sent_after = true; // Set a flag to indicate notification was sent
grAfter.update(); // Update the record to save the flag
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 12:06 AM
Do i have to define these fields somewhere or just use in schedule job? notification_sent_before and notification_sent_after

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 12:07 AM
Create 2 new fields on sc_req_item table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 12:08 AM
We can't create custom fields on that table @Omkar Mone