Incoming Contract Expiration Notifications

edupaz
Tera Contributor

Hello, 

Get notifications to the IT Managers group in advance when contracts are about to expire.

- Notifications should be sent to the IT Managers group.
- Send notifications 90 days before expiration.
- Send notifications 45 days before expiration.
- Send notifications 15 days before expiration.
- Send notification 1 day before expiration. (In this case, change the description and subject letting the IT Manager know it will expire tomorrow, instead of using the number of days)

Can somebody help me please?

1 ACCEPTED SOLUTION

Sumanth16
Kilo Patron

Hi @edupaz ,

You could do that with just a single event with a scheduled job.
Just create a scheduled job that runs daily. Then have it loop through your certificate table and for each record compare today to their expiry date. If the day is 90, 60, 30, 15 or 1 then you'll simply trigger the event with the amount of days left as one of the parameters.
In your notification you can just use the parm in the subject or in a script to decide how the notifications content looks like. Or if you want you can just trigger different events for each day and have separate notifications for them.

Here's a sample script. I've added a single if check but you can add more ifs for other dates if you want.

 

 

 

var certGr = new GlideRecord('sys_certificate');//update your table name
certGr.query();
while(certGr.next()) {
var expires= new GlideDateTime(certGr.expires);
var now = new GlideDateTime();
var dur = new GlideDuration();
dur = GlideDateTime.subtract(now, expires);
var days = dur.getDayPart();
if(days==1 ||days==30 || days == 60 || days == 30 || days==90){
gs.eventQueue("your_event_name", gr, "recipient", days);
}
}

 

 

 


 You could also add an query to only check for records that are expiring after today with
addQuery("expires>javascript:gs.endOfToday()");

 

Please mark as helpful/correct if it helps.

 

Thanks & Regards,
Sumanth Meda

View solution in original post

1 REPLY 1

Sumanth16
Kilo Patron

Hi @edupaz ,

You could do that with just a single event with a scheduled job.
Just create a scheduled job that runs daily. Then have it loop through your certificate table and for each record compare today to their expiry date. If the day is 90, 60, 30, 15 or 1 then you'll simply trigger the event with the amount of days left as one of the parameters.
In your notification you can just use the parm in the subject or in a script to decide how the notifications content looks like. Or if you want you can just trigger different events for each day and have separate notifications for them.

Here's a sample script. I've added a single if check but you can add more ifs for other dates if you want.

 

 

 

var certGr = new GlideRecord('sys_certificate');//update your table name
certGr.query();
while(certGr.next()) {
var expires= new GlideDateTime(certGr.expires);
var now = new GlideDateTime();
var dur = new GlideDuration();
dur = GlideDateTime.subtract(now, expires);
var days = dur.getDayPart();
if(days==1 ||days==30 || days == 60 || days == 30 || days==90){
gs.eventQueue("your_event_name", gr, "recipient", days);
}
}

 

 

 


 You could also add an query to only check for records that are expiring after today with
addQuery("expires>javascript:gs.endOfToday()");

 

Please mark as helpful/correct if it helps.

 

Thanks & Regards,
Sumanth Meda