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

Hi kalai,



I have changed the code this way, its filtering but still its giving the twice the number of records.


Like, I have 3 matching records but it is giving 6 log statements.



Any corrections?



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


  }


}


60 days records will also include the certificates of 30 days right ? Is it the reason for you to get more records ? If dont want 30 days record to be included in 60 days, change the query of 60 days gliderecord...


Sorry to bother you, but just wondering what will be the query for exact match?



Thanks!


Giving you an example and check if this works ....



After 30 days but before next 60 days



find_real_file.png



Next 30 days



find_real_file.png


I am trying this :


u_expiration_dateRELATIVEEE@dayofweek@ahead@30 (this seems correct, but not giving the results)



instead of : u_expiration_dateRELATIVELE@dayofweek@ahead@30


But its not giving me the records.



Also I tried example given by you, but still getting the same results.



Below is also not so helpful.


gr.addQuery('u_expiration_date','=','gs.daysAgo(-30)');