- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2023 03:34 AM
Hi ,
Need to configure email Notification for certificate expiry -before 90 days, 60,30,15,and 1 days
please help to configure
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2023 03:44 AM
Hi @rtrtungal39 ,
YOu can use the solution mentioned in the link : https://www.servicenow.com/community/developer-forum/i-want-to-send-mutiliple-notifications-on-certi...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2023 04:02 AM
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');
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 == 60 || days == 30){
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()");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2023 05:29 AM
Go to sysauto table and click new.
Select "Automatically run a script of your choosing"
Add this as the script:
var certGr = new GlideRecord('cmdb_ci_certificate');
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 == 60 || days == 30){
gs.eventQueue("certificate.expiring.90", gr, gr.<field_with_recipient>, days);
}
}
In the script you have to modify some things. I don't have a cmdb_ci_certificate table, so I'm not sure what the expires field is called there, but you'll have to change the expires GlideDateTime to check your field.
var expires= new GlideDateTime(certGr.expires);
//Change that into
var expires= new GlideDateTime(certGr.your_expiry_field);
In the gs.eventQueue you can change gr.<field_with_recipient> to whatever contains the recipient of the notification. For example if the certificate record has an owner field, then you'd probably set it to gr.owner.
In your notification you can add ${event.parm2} and it will be replaced with the value we have in days.
So for example a subject "Certificate ${name} is expiring in ${event.parm2} days" would print out
"Certificate XXX is expiring in 60 days"
In the "Who will receive" section of the notification you'll want to use event parm 1 contains recipient or if there's always someone specific then you can skip this.
Now on that single event (certificate.expiring.90) you'd now notify the user every 60 and 30 days that their certificate is expiring.
You can expand the if however you want by adding extra or conditions.
if(days == 90 || days == 60 || days == 30 || days == 15){
The scheduled job should be set to run daily, so that it checks each record every day.
Due to the above if, it would only send the notification when expiry is happening withing 90, 60, 30 or 15 days.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2023 03:44 AM
Hi @rtrtungal39 ,
YOu can use the solution mentioned in the link : https://www.servicenow.com/community/developer-forum/i-want-to-send-mutiliple-notifications-on-certi...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2023 04:02 AM
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');
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 == 60 || days == 30){
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()");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2023 04:50 AM
please guide me step wise .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2023 05:29 AM
Go to sysauto table and click new.
Select "Automatically run a script of your choosing"
Add this as the script:
var certGr = new GlideRecord('cmdb_ci_certificate');
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 == 60 || days == 30){
gs.eventQueue("certificate.expiring.90", gr, gr.<field_with_recipient>, days);
}
}
In the script you have to modify some things. I don't have a cmdb_ci_certificate table, so I'm not sure what the expires field is called there, but you'll have to change the expires GlideDateTime to check your field.
var expires= new GlideDateTime(certGr.expires);
//Change that into
var expires= new GlideDateTime(certGr.your_expiry_field);
In the gs.eventQueue you can change gr.<field_with_recipient> to whatever contains the recipient of the notification. For example if the certificate record has an owner field, then you'd probably set it to gr.owner.
In your notification you can add ${event.parm2} and it will be replaced with the value we have in days.
So for example a subject "Certificate ${name} is expiring in ${event.parm2} days" would print out
"Certificate XXX is expiring in 60 days"
In the "Who will receive" section of the notification you'll want to use event parm 1 contains recipient or if there's always someone specific then you can skip this.
Now on that single event (certificate.expiring.90) you'd now notify the user every 60 and 30 days that their certificate is expiring.
You can expand the if however you want by adding extra or conditions.
if(days == 90 || days == 60 || days == 30 || days == 15){
The scheduled job should be set to run daily, so that it checks each record every day.
Due to the above if, it would only send the notification when expiry is happening withing 90, 60, 30 or 15 days.