- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2015 02:19 AM
Hi,
I need to create Schedule job to generate notifications based on expiration of certificates. notification should be sent 60 or 30 days prior to the expiration.
Have created the following:
var cert = new GlideRecord('u_certificate');
cert.addQuery('u_expiration_date','<=',gs.daysAgo(-60));
cert.addQuery('u_expiration_date','<=',gs.daysAgo(-30));
cert.query();
while(cert.next()) {
if (u_expiration_date <= cert.u_expiration_date) {
gs.eventQueue("cert.expire.reminder", cert);
}
}
I need to send this notification to a group, which I am doing it via Email notification using the Event.
Please suggest.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2015 02:38 AM
Hi All,
I have got this fixed as below :
wmcFirstJob();
wmcSecondJob();
function wmcFirstJob()
{
var gr = new GlideRecord('u_certificate');
gr.addEncodedQuery('u_expiration_dateRELATIVEEE@dayofweek@ahead@30');
gr.query();
while(gr.next()){
gs.eventQueue("cert.expire.reminder",gr,30);
}
}
function wmcSecondJob()
{
var gr = new GlideRecord('u_certificate');
gr.addEncodedQuery('u_expiration_dateRELATIVEEE@dayofweek@ahead@60');
gr.query();
while (gr.next()){
gs.eventQueue("cert.expire.reminder",gr,60);
}
Thanks Pradeep and Kalai!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2015 04:57 AM
Hi Basha,
This encoded query is working but I want to send different messages on 60 and 30 day expiration?
Any suggestions?
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2015 09:37 AM
Hi Jyo,
Can you try this and let me know if you face any problem.
firstJob();
secondJob();
function firstJob()
{
var gr = new GlideRecord('table');
gr.addQuery('active=true^u_expiration_dateONToday@javascript:gs.daysAgoStart(30));
gr.query()
while(gr.next()){
fire the event
//line above will fire an event against each record found
}
}
function secondJob()
{
var gr = new GlideRecord('table');
gr.addQuery(''active=true^u_expiration_dateONToday@javascript:gs.daysAgoStart(60));
gr.query();
while (gr.next()){
fire the event
//Create the new notificaiton here and fire the event
}
}
I have not tested this but this should work for you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2015 09:41 PM
Pradeep's code is the way to go .... Have separate events and related email notifications and fire those in the respective loops.. Should do the job ..
Also did you look into Doug's comment ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2015 09:55 PM
Hi pardeep,
The below script was working correctly, I am just not able to fire the events correctly.
I want to fire events twice, once if it finds a match for 30 days and another for 60 days.Your script wasn't filtering the records.
//
var gr = new GlideRecord('u_certificate');
gr.addEncodedQuery('active=true^u_expiration_dateRELATIVELE@dayofweek@ahead@30^ORu_expiration_dateRELATIVELE@dayofweek@ahead@60');
//query above would find records active whose expiration date field value is 30 and 60 days from current date
gr.query();
while (gr.next()){
gs.log("Notification sent for 60 days");
//line above will fire an event against each record found
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2015 09:58 PM
You have made use of both the queries in one glide record .. Just split the query and do 2 gliderecords .. One for 30 days and the other for 60 days...