How to Rearchive restored records

sagarikadas
Kilo Contributor

Hello Everyone,

I have around 8700 restored records from knowledge table which needs to be archived again.

But while running a new Archive Rule I see below error message.

Running archive rule: Archiving older Knowledge Articles from KB V2. 9503 record(s) cannot be re-archived because they have been restored.

Can anyone please advise.

Regards,

Sagarika Das

1 ACCEPTED SOLUTION

First of all, if it's a one time off, you shouldn't use a UI action for it. You should maybe create a scheduled script execution.



And you need to adapt your script a bit. Does this work for one record if you run it via background scripts?



var gr = new GlideRecord('ar_kb_knowledge');


gr.addQuery('kb_knowledge_base','dfc19531bf2021003f07e2c1ac0739ab');


gr.addQuery('dateGenerate','<','2017-01-01','12:00:00');


gr.addQuery('category','Planned Downtime');


gr.addOrCondition('category','Unplanned Downtime');


gr.setLimit(1);


gr.query();




while(gr.next()) {


  gs.print('Archiving record with number: ' + gr.number);


  try {


      new GlideArchiveRecord().archive(gr);


  }


  catch(err) {


      gs.log('Error returned is: ' + err);


  }


}


View solution in original post

21 REPLIES 21

Basically, the Archive job doesn't pick records once you have restored them, but this doesn't mean that it cannot be archived again.


Chandra2
Tera Contributor

Try the below script for one records you will archive the restored archive records ,I tried in my Non prod instance and it working as expected:

var gr = new GlideRecord(‘cmdb_ci_win_server’);
gr.addQuery('name','CI name');  //put record name
gr.query();
while (gr.next()) {
if (gr.get(gr.sys_id))
{
var archiver = new GlideArchiveRecord();
archiver.archive(gr);
}
}

if it help you please mark as helpful