Send notification based on date of event

Andre241
Tera Contributor

Hello,

 

I have a requirement to send out a notification based on.

 

  • Number of options remaining is greater than zero
  • Should be sent 90 days prior to the current period of performance end date

How would I do this in the email notification configuration? Actual steps would be very helpful. Thank you.

1 ACCEPTED SOLUTION

Maddysunil
Kilo Sage

@Andre241 

You can run a schedule job on daily basis , you can modify below script

var currentDate = new GlideDateTime();
    
    // Calculate the target date (90 days prior to the current period of performance end date)
    var targetDate = new GlideDateTime(); // Assuming 'currentRecord' is the record you're working with
    targetDate.setDisplayValue(currentRecord.u_period_of_performance_end_date); // Replace with the actual field name

    // Calculate the difference in days
    var daysDifference = GlideDate.subtract(targetDate, currentDate);

    // Check conditions
    if (currentRecord.u_options_remaining > 0 && daysDifference > 90) {
        // Send notification logic here
        gs.eventQueue('notification.event.type', currentRecord, '90 days notification');
    }

 Please mark my answer correct/helpful if it helps you!

View solution in original post

5 REPLIES 5

Mitesh L Pitrod
Tera Contributor

Hello,

You can use a scheduled job to Glide the table and filter the records that satisfy the condition and trigger an event to send the email for those records.

 

Thank you,

Mitesh.

Andre241_0-1707792816206.png

Andre241_1-1707793055773.png

 

 

Would me running it periodically with 90 days be correct based on my requirements? I've never created a scheduled job before and I'm wrecking myself trying to figure this out.

The scheduled job should run daily as there is a possibility that there will be a new record everyday that has performance end date as 90 days from the today.

 

Please mark my answer as helpful if it solves your issue.

Thanks.

Sumanth16
Kilo Patron

Hi, 

create scheduled job with below code:

 

 

 var chkDate = new GlideDate();
chkDate.addDays(90);
var rec = new GlideRecord('u_infra_certificates');//replace your table name
rec.addQuery('u_cert_expiry_date', chkDate); //replace with your date field
rec.query();
while (rec.next()) {
gs.eventQueue("knowledge.expiring", rec, event,parm1,event.parm2);
}

Please hit like and mark my response as correct if that helps

Thanks & Regards,
Sumanth Meda.