Reminder Notifications to be triggered based on date field for 72 ,48 and 24 Hours respectively.

Kruthik M Shiva
Tera Contributor

Hi All,
I have a requirement for sending reminder notifications based on date field, i.e. based on the date given the reminder has to be sent before 72,48 and 24 hours.
Scenario: I have a choice field called corrective action where we have 5 choices 1,2,3,4,5 so based on the selection date field will be populated so if they select 1 as choice 1 date field will be populated and if they select 5 as choice 5 date will be populated, so based on the choice we have to send reminder notifications if they have selected 1 for only that date field the reminder notifications has to be sent. So can anyone please explain what all needs to be done for this also please do provide the script required for this for complete process. 
Thanks in advance,
Kruthik

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Kruthik M Shiva 

You will need following elements to achieve this requirement.

1. An event (Created via Event registry)

2. A notification triggered via the event created in step 1

3. A scripted scheduled job which will trigger the event

You should create a scripted scheduled job which will run every day and fetch the records from your table.You can add filters using addActiveQuery() to get the active records and use addQuery to filter all those records where your corrective action date matches with the today's date. 

For all such records you need to trigger the event which will in turn trigger the notification.

 

Hope this helps.

SN_Learn
Kilo Patron
Kilo Patron

Hi @Kruthik M Shiva ,

 

Please have a look at the sample code below, update the query conditions and field names accordingly.

 

 

var todayDT = new GlideDate();

var gr = new GlideRecord('incident');
gr.addQuery('sys_id', current.sys_id);
gr.query();
if (gr.next()) {
    //Update it with Corrective action backend name

    if (gr.corrective_action == '1') {
        var getDate = gr.u_date_field1; //Update it with the respective date field's backend name
        var findDtDiff = gs.dateDiff(todayDT, getDate, true);
        var convertDay = parseInt((findDtDiff) / 86400); //Get the day diff
        //If 24, 48, or 74 hours left then it will trigger the below notification.
        if (convertDay == 1 || convertDay == 2 || convertDay == 3) {
            gs.eventQueue('event.name1', current, current.number, gs.getUserName());
        }
    }

    if (gr.corrective_action == '2') {
        var getDate2 = gr.u_date_field2; //Update it with the respective date field's backend name
        var findDtDiff2 = gs.dateDiff(todayDT, getDate2, true);
        var convertDay2 = parseInt((findDtDiff2) / 86400); //Get the day diff
        if (convertDay2 == 1 || convertDay2 == 2 || convertDay2 == 3) {
            gs.eventQueue('event.name2', current, current.number, gs.getUserName());
        }
    }
}

 

 

Event need to be created in the [sysevent_register] table and create new notifications which will be triggered by event.

The above code covers for 'corrective_action' value 1 and 2. Similarly, you need to create for rest of the scenario.

 

 

Please mark this answer as Correct/Helpful if it was really helpful for you.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.