how to restore multiple archived incidents

chandana16
Tera Contributor

Hello All,

 

I want to restore some 15 k incidents from archive table.

can you please give a suggestions.

Thank you.

14 REPLIES 14

Karan Chhabra6
Mega Sage
Mega Sage

Hi @chandana16  - do you want to restore the related records as well??

if possible yes. otherwise without related records also fine

 

@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

 

@karan : in the below line what does 'from_table=incident' indicates ?

 and can we replace that with 'number=INC000XXX'; ??