Notification Trigger Condition

Bijay Kumar Sha
Giga Guru

I've below fields which captures the future dates (Next Review Date) - 

 

Risk Next Review Date
Criticality Next Review Date
PIA Next Review Date
Architecture Next Review Date
Security Next Review Date
Exit Strategy Next Review Date

 

Now, I wanted to have Notification Trigger for upcoming compliance items deadlines. Below are the conditions - 

- at the first day of each calendar month will check for each and every Accounts if any of the accounts have either: upcoming compliance deadlines this months or already overdue compliance items

- repeat next month if any condition is met

 

So, how the scheduled job will check all the accounts if the due date falls under current month or not. 

 

2 REPLIES 2

Amit Gujarathi
Giga Sage
Giga Sage

HI @Bijay Kumar Sha ,
I trust you are doing great.
Please try the below script for the same

// Query all accounts
var accountGR = new GlideRecord('your_account_table_name'); // Replace 'your_account_table_name' with the actual table name
accountGR.query();

while (accountGR.next()) {
    var currentDate = new GlideDate();
    var currentMonth = currentDate.getByFormat('MM');
    var currentYear = currentDate.getByFormat('yyyy');

    // List of fields to check
    var fields = [
        'risk_next_review_date',
        'criticality_next_review_date',
        'pia_next_review_date',
        'architecture_next_review_date',
        'security_next_review_date',
        'exit_strategy_next_review_date'
    ];

    var notifyFlag = false; // Flag to check if notification needs to be sent

    for (var i = 0; i < fields.length; i++) {
        var reviewDate = accountGR.getValue(fields[i]);
        if (reviewDate) {
            var reviewGlideDate = new GlideDate();
            reviewGlideDate.setValue(reviewDate);
            var reviewMonth = reviewGlideDate.getByFormat('MM');
            var reviewYear = reviewGlideDate.getByFormat('yyyy');

            // Check if review date is in the current month or is already overdue
            if ((reviewMonth == currentMonth && reviewYear == currentYear) || reviewGlideDate.before(currentDate)) {
                notifyFlag = true;
                break;
            }
        }
    }

    if (notifyFlag) {
        // Send Notification
        // You can use the gs.eventQueue() method or any other notification mechanism
        gs.eventQueue('custom_event_name', accountGR, 'message', 'additional_info'); // Replace placeholders with actual values
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi @Amit Gujarathi ,

Just one modification, notification will get triggered on the 1st day of Calendar month but it'll check if the next review date is in both current month AND next month, then notification will get trigger.

So, what modification needs to be done above code?