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

Are you getting the correct results on filtering in table ?


Nope, no results at all.



The below code is   working correct otherwise, except the notifications which are getting generated on the Certificate is expiring "on or before" 30 days. I am just looking to fix it for one reminder that is when certificate expires exactly after 30 days.


No multiple reminder notifications.


=========================================================


firstJob();


secondJob();


function firstJob()


{


  var gr = new GlideRecord('u_certificate');


  gr.addEncodedQuery('u_expiration_dateRELATIVELE@dayofweek@ahead@60');


  gr.query();


  while(gr.next()){


  gs.log("Notification sent to users 60");


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


  }


}


function secondJob()


{


  var gr = new GlideRecord('u_certificate');


  gr.addEncodedQuery('u_expiration_dateRELATIVELE@dayofweek@ahead@30');


  gr.query();


  while (gr.next()){


  gs.log("Notification sent to users 30");


  //fire the event


  //Create the new notificaiton here and fire the event


  }


}


=========================================================


Thanks!


randrews
Tera Guru

are these certificatons in SN or just web certs you have external and are loading into a table.. the reason i am asking is this should be built in OOB if you enter the certs into the cert area of the ldap settings   in SN


These are Certificate Records in SN.


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