- 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-10-2024 02:35 AM
I don't think we can cpmpare the field date with today's date @Omkar Mone because its not working...we just need to check if th field date is 15 we need to send one noti on 14 and one on 16..onedaybefore and onedayafter

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 03:06 AM - edited ‎10-10-2024 03:08 AM
Hello Priyanka,
I feel you are not getting the variable value properly in your code. The code I gave is just for your reference,
I see you want to get value from a variable. you need to do it something like below
Here is the revised code from what I gave you which you need to update.
var catalogItemSysId = '09d6e9b5932a0214c563ba6efaba10d2';
var variableDateField = 'u_start_date';
// Handle one day before the variable date
var grBefore = new GlideRecord('sc_req_item');
grBefore.addQuery('sys_id','your_RITM_sys_id');//replace here
grBefore.addQuery('cat_item', catalogItemSysId);
grBefore.query();
while (grBefore.next()) {
var dt = grBefore.variables[variableDateField];; // it needs to be done like this.
var expectedDate = new GlideDateTime(dt);
var today = new GlideDateTime();
today.addDays(-1); // Subtract 1 day to compare with the date field
// Compare the date part only (ignores the time)
if (expectedDate.getDate().getDisplayValue() == today.getDate().getDisplayValue()) {
gs.eventQueue('event.before', grBefore, grBefore.requested_for, '');
}
}
// Handle one day after the variable date
var grAfter = new GlideRecord('sc_req_item');
grAfter.addQuery('sys_id','6577736d47085e1054fa4df8736d432f');//replace it
grAfter.addQuery('cat_item', catalogItemSysId);
grAfter.query();
while (grAfter.next()) {
var dtAft = grBefore.variables[variableDateField];
var expectedDateAfter = new GlideDateTime(dtAft);
var todayAfter = new GlideDateTime();
todayAfter.addDays(1); // Add 1 day to compare with the date field
if (expectedDateAfter.getDate().getDisplayValue() == todayAfter.getDate().getDisplayValue()) {
gs.eventQueue('event.after', grAfter, grAfter.requested_for, '');
}
}
Hope this clarifies.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 04:24 AM
I am using this script @Omkar Mone and its trigerring email for previously created RITM where the date was 9oct and it should not trigger that emails because today its already 10oct if date is 9oct that email should have been triggered only on 8 oct for before notification

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 07:59 PM
Hello Priyanka,
You said here it was working. It sent out a notif yesterday because the date was the 9th and yesterday was the 10th which is after 1 day (as per your scenario). It seems to me that it's working as intended. not sure what is missing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 09:58 PM
It was working for RITM where date field was 9 so it was triggering before noti also but before should go on 8 it should only trigger after yesterday...and now its not working only