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

bashashaik
Giga Contributor

Hi,



Please refer this thread and modify code as per your requirement



we need to create schedule job but i am not sure how to do and how to trigger notification?


Harish Murikina
Tera Guru

Here you go.....





var cert = new GlideRecord('u_certificate');


var qc = cert.addQuery('u_expiration_date','<=', gs.daysAgo(-60));


qc.addOrCondition('u_expiration_date', '<=',gs.daysAgo(-60));


cert.query();


while(cert.next())


{



    gs.eventQueue("change.updated", cert, abc, xyz);


    //change.updated -- Event name


    //cert -- Pass the glide object


    //ABC -- Mail id which to whome you want to send


    //XYZ -- Mail id which to whome you want to send


  }


Hey Harish!



Why we are using the same condition twice, you mean 30 in the second line?


var qc = cert.addQuery('u_expiration_date','<=', gs.daysAgo(-60));


qc.addOrCondition('u_expiration_date', '<=',gs.daysAgo(-60));



Actually, I need an If condition as well coz I need this job to send the notification before 60 days as well as 30 days.



Please help.


then repalce one 60 with 30



var cert = new GlideRecord('u_certificate');


var qc = cert.addQuery('u_expiration_date','<=', gs.daysAgo(-30));


qc.addOrCondition('u_expiration_date', '<=',gs.daysAgo(-60));


cert.query();


while(cert.next())


{



    gs.eventQueue("change.updated", cert, abc, xyz);


    //change.updated -- Event name


    //cert -- Pass the glide object


    //ABC -- Mail id which to whome you want to send


    //XYZ -- Mail id which to whome you want to send


  }