How to write a scheduled job for knowledge article expires in 30 days?

sayalimore
Kilo Expert

Hello all,

I want to trigger a notification which has to be sent when knowledge article is set to be expired in next 30 days, through scheduled job.

The event name is knowledge.valid.to.expiring.

Thanks

Sayali

6 REPLIES 6

Chuck Tomasi
Tera Patron

Hi Sayali,



You'll need to create a new field on the kb_knowledge table to track which ones have been notified and which have not. A simple true/false field will do this. From there, create a scheduled nightly script to run (System Definition> Scheduled Jobs)



The script looks something like this:


Standard disclaimer: The following code is untested, requires review and potential modifications.



(function () {


      var rec = new GlideRecord('kb_knowledge');


      rec.addQuery('valid_to', '<=', gs.daysAgo(-30));


      rec.addQuery('u_notified', false); // YOUR NEW FIELD HERE


      rec.query();



      while (rec.next()) {


          gs.eventQueue('knowledge.valid.to.expiring', rec, '', '');


      rec.u_notified = true;


      rec.update();


  rec.update();


      }


})();


Chuck, this is helpful.   Instead of having it less than 30 days, how would you change this to catch expiring articles at exactly 30 days?


Hi Brian,



I invite you to take a look at a scriptless solution to this which makes it much easier to define the criteria.



Scriptless Scheduled Jobs



(Despite the article saying Geneva is not supported, the update set works - just ignore the preview errors.)


Thank you Chuck!   I will check this video and load it into my dev instance.   I'm still trying to get familiar with scripting, so this will be a big help!   I do have another few questions for you.   We have an issue with knowledge articles passing their valid-to dates but are staying in a published state.   Because of this, the articles can not be searched.   With the tool you provided I'm going to set up notifications to help keep this from happening, but in the event these articles are not renewed, we would like to have the article move to the pending retirement state if not updated before expiration.   This should trigger the retire approval workflow, giving the assignment group another notification.   My question(s), would be is this the best way to keep articles from being published but expired and what would be the best route to do this? I was thinking a business rule to change the state based on the criteria above.   Curious on your thoughts.



Thanks again for your help!