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

20 REPLIES 20

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);


  }


}


Thank You Sergiu !!



It indeed a right way to re-archive.


One more advise is needed from you.. What if I want to restore a bunch of archived records(8000) ??


Especially when I do not wish to use List choice to restore.


Can I use any Background script??



Regards,


Sagarika


Yes, you can restore archived records with a script as well. Background scripts might not be a good idea, you should actually use a scheduled script execution.



What kind of conditions do you need to use for restore?


Hi Sergiu,



Just curious to know why Background scripts isn't a good Idea.


I actually wanted to archive 9000 old KB articles(which are older than this Year and based on some Category conditions).


And this should be a one time Archive. Please advise.



Regards,


Sagarika Das


If you run it via Background Scripts then your session will be blocked by that transaction (due to Session Synchronizer and you won't be able to do anything else in the instance within the same browser). You'll need to login either via another browser or via an incognito session (a new session) to have access to the instance.