Schedule jobs to generate notifications based on expiration of certificates

Jyoti36
Mega Expert

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!

1 ACCEPTED SOLUTION

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!!


View solution in original post

26 REPLIES 26

I want to calculate the difference that is:


if difference between current date and u_expiration_date is 60 then send an event 60 ee if its 30 then send an event 30.


We can calculate the difference.



Can you tell me if the difference between current date and expire date is 60 what your doing here.


Hi,



first, find the records something like this.


var gr = new GlideRecord('table');


gr.addEncodedQuery('active=true^u_expiration_dateONToday@javascript:gs.daysAgoStart(30)^u_expiration_dateONToday@javascript:gs.daysAgoStart(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.eventQuery('expiration.date.reached',gr);


//line above will fire an event against each record found


}



Creating a Scheduled Job - ServiceNow Wiki


Events and Email Notification - ServiceNow Wiki


I want to do soething like this :



If ((calculate diff here,between current date and expire date) is 60)


{


gs.eventQuery('expiration.date.reached',60);


}


else If ((calculate diff here,between current date and expire date) is 30)


{


gs.eventQuery('expiration.date.reached',30);


}






Hi Jyo,


Have you tried Inactivity monitor service now feature: You buid your conditions and send notification e-mail by using table.inactivity event if certificated have not updated ?



regards,