- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2017 03:27 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2017 04:09 AM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2017 01:27 AM
Something like:
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('field1','value1');
gr.addQuery('field2','vale2');
gr.setLimit(5);
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);
}
}
You need to adapt the query to match your conditions.
Play on a subprod instance, never directly on prod.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2017 01:37 AM
Hi Sergiu,
I believe new GlideArchiveRecord().archive(gr); will archive the records.
But i wanted to Retrieve/Restored the already archived Records by using script.
Regards,
Sagarika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2017 02:14 AM
Sorry, got distracted with other things and missed the fact that you want to restore , not archive.
This is one way, but you need to adapt the encoded query to match your conditions:
var gr = new GlideRecord('sys_archive_log');
gr.addEncodedQuery('restoredISEMPTY^from_tableINkb_knowledge');
gr.query();
while(gr.next()) {
try {
var und = new GlideArchiveRestore().restore(gr.sys_id);
}
catch(err) {
gs.log('Error returned is: ' + err);
continue;
}
}
The other thing here is that you will need to remove these records from sys_archive_log as well, otherwise you won't be able to re-archive them at a later stage.
Again, test this on subprod.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2017 10:15 PM
Thanks Sergiu!!
I shall try this on Development Environment and get back to you. Once again thank you for all your advise.
Regards,
Sagarika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 09:56 AM
Hi Sagarika,
Did you get any script to restore bulk records?