- 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 10:01 PM
I don't think it trigger before notif, it must have triggered after, can you show the event log?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 04:27 AM - edited ‎10-10-2024 04:28 AM
It is comparing the date field value from item there its 9 oct today its 10 so 10-1 is 9 if 9=9 its triggering email but that is wrong? We want if date field is put as 11 and submitted item so today it should trigger email for that RITM??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 06:43 PM
Hello
Can you try the below code?
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);
var today = new GlideDateTime();
today.addDays(-1);
if (expectedDate.getDisplayValue() > today.getDisplayValue()) {
if (expectedDate.getDate().getDisplayValue() == today.getDate().getDisplayValue()) {
gs.eventQueue('event.before', grBefore, grBefore.requested_for, '');
}
}
}
}
var grAfter = new GlideRecord('sc_req_item');
grAfter.addQuery('cat_item', catalogItemSysId);
grAfter.query();
while (grAfter.next()) {
var dtAft = grAfter.variables[variableDateField];
if (dtAft) {
var expectedDateAfter = new GlideDateTime(dtAft);
var todayAfter = new GlideDateTime();
todayAfter.addDays(1);
if (expectedDateAfter.getDisplayValue() > todayAfter.getDisplayValue()) {
if (expectedDateAfter.getDate().getDisplayValue() == todayAfter.getDate().getDisplayValue()) {
gs.eventQueue('event.after', grAfter, grAfter.requested_for, '');
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 07:15 PM - edited ‎10-10-2024 07:17 PM
This script is not working only not triggering any notification @Omkar Mone ....Just take my scenerio and try to built if you can if date field in form is put as 12 oct before noti on 11 and after on 13 nothing else...no other day it should trigger only on 11 and 13....not working anything

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2024 07:41 PM
Hello Priyanka,
The script is intended to send notifs only on the day before and after. I am not sure how it is not working at your end, is it something to do with the timezone?
because the code
if (expectedDate.getDisplayValue() > today.getDisplayValue())
is responsible to see if the date is greater, the don't trigger anything.