Script to restore old emails to an Incident

CV1
Tera Contributor

Hi All,

Looking for background script to restore old emails from Table : ar_sys_email .There are around 60 emails for an inc that need to be restored.

 

TIA

3 REPLIES 3

chetanb
Tera Guru

@CV1 , I would recommend better to - use ServiceNow import sets if you have backed up file containing delete emails or involve ServiceNow support as they have expertise and tools to safely restore deleted emails data while maintaining data integrity and security concerns as well.

 

Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

 

Regards,

CB

CV1
Tera Contributor

@chetanb ,

We want to restore emails for only 2 old incidents and not for all and since there are many emails for these 2 incs restoring it one by one is time consuming. so looking for a script .

TIA

DYCM
Mega Sage

Hi @CV1 ,

Restoring old emails from: ar_sys_email, you can collect their id from sys_archive_log table 

1.png

 

Then update the following code snippet to restore them in a loop

var emailArchive = new GlideRecord('sys_archive_log');
emailArchive.addQuery('id', "139f982b9710c6104c2eff36f053afa6");
emailArchive.addNullQuery('restored');
emailArchive.query();
if (emailArchive.next()) {
	gs.info("Found Achive!");
    var und = new GlideArchiveRestore().restore(emailArchive.sys_id);
    if (!und) {
        gs.info("The restore failed");
    } else {
        gs.info("Archive restored");

    }
}
else{
	gs.info("Achive Not Found!");
}

 

Here is the result:

2.png