Retire KB Automatically

rc393g
Kilo Explorer

Hi All,

I would like to seek you help on how I can verify that our Knowledge Article will be retired after the valid to date. Will this be OOB in Fuji for Knowledge Management.

Appreciate your help!

1 ACCEPTED SOLUTION

Tanaji Patil
Tera Guru

Hi,



Use this code-



var kb = new GlideRecord('kb_knowledge');


kb.addQuery('workflow_state','!=','retired');


kb.addQuery('valid_to','<',gs.now().toString());


kb.query();


while(kb.next()){


  var workflow = new Workflow();


  workflow.cancel(kb);         //this will cancel all workflow contexts with the record


  kb.workflow_state = 'retired';


  kb.update();


}



This should work.



If you are using workflow for knowledge article flow then I would recommend you to use 'Wait for condition' with condition 'valid to at or before Today' followed by 'Set values' activity.



Have a good day



Thanks,


Tanaji


View solution in original post

11 REPLIES 11

Something like this ought to do it:


Capture.PNG


Thanks for this, Mike! I was also able to reference in our Wiki -- Legacy:Retire Expired Knowledge Base Articles - ServiceNow Wiki



But, when I click on Execute Now, it still does not work. The article remains published. Hope to hear for your usual help and advise. Thank you in advance! Know Your Expert | Pradeep Sharma


Hi,



Can you try to reproduce this on any demo instance so that I can take a look.



Thanks,


Pradeep Sharma


pardhu3
Giga Contributor

Can you please check on in the scheduled jobs.the script definetly will be in it. You can also check on "Knowledge email expiraion" scheduled job.why because in some case in the same scheduled job only they will write code for both state change and email notification.


Thanks,


Pardhu Guduru.


Hi Pardhu, There is currently no OOB for KB in Scheduled Jobs including the one you mentioned.