How to send notifications before due dates

Sanket Pawar
Tera Contributor

Hi All,

I have a requirement where,

 

I have a date field value_date,and when I am working on a ticket that is in the "New status", notifications should be sent to requestor in below conditions:

1. Five business days before the value date
2. One business day before the value date
3. On the value date
4. One business day after the value date
 
 I have created a schedule job to fulfill this requirement, but the schedule job is triggering notifications daily besides these condition,
ideally the schedule job  should trigger notification only when the conditions in below function satisfy
for example if iam executing the function onedaybefore(),then the email is getting triggered everyday that should not be the case.
 
 
script:
fivedaysbefore();
onedaybefore();
currentday();
onedayafter();

function fivedaysbefore() {
    var mn = new GlideRecord('x_cacei_s2p_payment');
    mn.addEncodedQuery('u_value_dateRELATIVEGT@dayofweek@ahead@5^state=1^active=true');
    mn.query();
    while (mn.next()) {
        gs.eventQueue('x_cacei_s2p.manualpayment',mn);
    }
}

function onedaybefore() {
    var mn = new GlideRecord('x_cacei_s2p_payment');
    mn.addEncodedQuery('u_value_dateONTomorrow@javascript:gs.beginningOfTomorrow()@javascript:gs.endOfTomorrow()^state=1^active=true');
    mn.query();
    while (mn.next()) {
        gs.eventQueue('x_cacei_s2p.manualpayment',mn);
    }
}

function currentday() {
    var mn = new GlideRecord('x_cacei_s2p_payment');
    mn.addEncodedQuery('u_value_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^state=1^active=true');
    mn.query();
    while (mn.next()) {
        gs.eventQueue('x_cacei_s2p.manualpayment',mn);
    }
}

function onedayafter() {
    var mn = new GlideRecord('x_cacei_s2p_payment');
    mn.addEncodedQuery('u_value_dateONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()^state=1^active=true');
    mn.query();
    while (mn.next()) {
        gs.eventQueue('x_cacei_s2p.manualpayment',mn);
    }

}

 

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, I suspect that your issue is you are not filtering for a period between dates.

IE for fivedaysbefore() your filter is 'u_value_dateRELATIVEGT@dayofweek@ahead@5'

but this needs to capture a window using before\after so that you only trigger fivedaysbefore() once per record (when fivedaysbefore() is run daily).

EG

'start_dateRELATIVEGT@dayofweek@ahead@4^start_dateRELATIVELT@dayofweek@ahead@6'

 

/now/nav/ui/classic/params/target/change_request_list.do%3Fsysparm_query%3Dstart_dateRELATIVEGT%40dayofweek%40ahead%404%255Estart_dateRELATIVELT%40dayofweek%40ahead%406%26sysparm_first_row%3D1%26sysparm_view%3D

 

From experience, the best way to ensure that queries of this nature are correct.
is by configuring filters on a list view, ensure that you have sufficient sample data to cover all date variations.