how to restore multiple archived incidents
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 12:26 AM
Hello All,
I want to restore some 15 k incidents from archive table.
can you please give a suggestions.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 12:57 AM
Hi @chandana16 - do you want to restore the related records as well??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 01:00 AM
if possible yes. otherwise without related records also fine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 02:07 AM
@chandana16 - you can use fix script for this, leverage the GlideArchiveRestore().restore() method
Here's the fix script - modify the encoded query so that it fetches all the records you need from the archive table - this is without related records
restoreRecords();
function restoreRecords() {
var archiveGR = new GlideRecord('sys_archive_log');
archiveGR.addEncodedQuery('from_table=incident'); // modify the encoded query, add more filters
archiveGR.query();
while (archiveGR.next()) {
new GlideArchiveRestore().restore(archiveGR.sys_id);
}
}
Restoration with related records:
restoreRecords();
function restoreRecords() {
var archiveGR = new GlideRecord('sys_archive_log');
archiveGR.addEncodedQuery('from_table=incident'); // modify the encoded query, add more filters
archiveGR.query();
while (archiveGR.next()) {
new GlideArchiveRestore().restore(archiveGR.sys_id);
var grArchiveRel = new GlideRecord("sys_archive_related");
grArchiveRel.addQuery("archive_map", archiveGR.archive);
grArchiveRel.query();
while (grArchiveRel.next()) {
var gr2 = new GlideRecord("sys_archive_log");
gr2.addQuery("archive_run", archiveGR.archive_run);
gr2.query();
while (gr2.next()) {
if (gs.getXMLText(gr2.payload, "//" + grArchiveRel.element) == archiveGR.id)
new GlideArchiveRestore().restore(gr2.sys_id);
}
}
}
}
Test it out for single record first then you can proceed with all the records.
If my answer has helped with your question, please mark it as correct and helpful
Thanks,
Karan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 03:12 AM
@karan : in the below line what does 'from_table=incident' indicates ?
and can we replace that with 'number=INC000XXX'; ??