I need to receive notifications alerting me that my engagement is due for periodic review in 12/9/6

Nikhitha Gandhi
Tera Contributor

Requirement:

Create four notification templates that each adhere to the following format. Each timeframe (12 months, 9 months, 6 months, 3 months) should have its own template.

Name: Periodic Review Due {12 months, 9 months, 6 months, or 3 months}
Trigger: Engagement's periodic review date is in {12 months, 9 months, 6 months, or 3 months}
Recipients: "Business Owner" on engagement record
Subject: Your third-party engagement is due for periodic review in {12 months, 9 months, 6 months, or 3 months}

 

Code: The below code is triggering daily. Help me with the code correction to trigger it exactly on 12/9/6/3 months.

 

var grecEng = new GlideRecord('sn_vdr_risk_asmt_vendor_engagement');
grecEng.addEncodedQuery('u_periodic_review_dateISNOTEMPTY^u_periodic_review_dateRELATIVEGT@dayofweek@ahead@89');
grecEng.query(); //Checks if periodic review is not empty and periodic review date is greater than 89 days.
while (grecEng.next()) {
    // Create GlideDateTime objects for the two dates
    var startDate = new GlideDateTime();
    var endDate = new GlideDateTime(grecEng.u_periodic_review_date);

    // Calculate the difference in months and days
    var monthsDifference = endDate.getMonth() - startDate.getMonth() +
        (endDate.getYear() - startDate.getYear()) * 12;

    if (monthsDifference == 3) {
        gs.eventQueue('sn_vdr_risk_asmt.abt_periodic_review_thr', grecEng, grecEng.business_owners);
    } else if (monthsDifference == 6) {
        gs.eventQueue('sn_vdr_risk_asmt.abt_periodic_review_six', grecEng, grecEng.business_owners);
    } else if (monthsDifference == 9) {
        gs.eventQueue('sn_vdr_risk_asmt.abt_periodic_review_nin', grecEng, grecEng.business_owners);
    } else if (monthsDifference == 12) {
        gs.eventQueue('sn_vdr_risk_asmt.abt_periodic_review_twe', grecEng, grecEng.business_owners);
    }
}
0 REPLIES 0