Notification remainders for due 60 days

Mohammed Ameen
Tera Contributor

Hello Experts,

 

Scenario: In policy form we have a fields called "valid to" and "approver" , if a person selects the policy valid to date as 25-03-2024, then it should send the notification to the Approver.

For example: Valid To field count the days from today to exact 60 days, 25-01-2024 - 25-03-2024 = 2months = 60 days.

 

Solution: I have created the notification and scheduled job and event queue 

In scheduled job script I am facing the issue.

I tried multiple scripts but it is not working as expected

 

Script 1: 

var Due60days = new GlideDate();
Due60days.addDaysLocalTime(60);
var policyIn = new GlideRecord("sn_compliance_policy");
policyIn.addQuery("valid_to", "=",  Due60days);
//policyIn.addEncodedQuery("valid_to", cDate);
policyIn.query();
while(policyIn.next()){
gs.eventQueue("sn_compliance.sn_policy_60days_due_date", policyIn);
}
 
 
Script 2: 
var policyIn = new GlideRecord("sn_compliance_policy");
//policyIn.addEncodedQuery("valid_to");
policyIn.query();
while(policyIn.next()){
    var Due60days = new GlideDateTime(policyIn.valide_to).getDate();
    if(Due60days.addDays(-60)==new GlideDateTime.getDate()){
        gs.eventQueue("sn_compliance.sn_policy_60days_due_date", policyIn);
    }
}
 
Script 3:
var policyIn = new GlideRecord("sn_compliance_policy");
//policyIn.addQuery("valid_to", "=");
policyIn.query();
while(policyIn.next()){
    var startDate2 = policyIn.getValue("valid_to");
    //check dates
    var Due60days = new GlideDateTime();
    Due60days.setValue(startDate2);
    var end2 = new GlideDateTime();
    var diff2 = GlideDateTime.substract(Due60days, end2 );
    var days2 = diff2.getRoundedDaypart();
    //Send Notifications
    if(days2 == 1){
        gs.eventQueue("sn_compliance.sn_policy_60days_due_date", policyIn);
    }
}
 
Non of the above scripts are working as expected.
Note: I need notification on exact 60 days not greater than 60 days, by using above scripts notifications are getting triggered for every policy policy whose days are greater than 60 days which is not a requirement, I need a notification to trigger on exact 60 days as mentioned above.
1 REPLY 1

Mark Manders
Mega Patron
var policyIn = new GlideRecord("sn_compliancy_policy");
policyIn.addEncodedQuery('valid_toRELATIVEGT@dayofweek@ahead@59^valid_toRELATIVELT@dayofweek@ahead@61');
policyIn.query();
while(policyIn.next()){
   gs.eventQueue("sn_compliance.sn_policy_60days_due_date",policyIn");
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark