Script to restore old emails to an Incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 07:46 PM - edited 02-16-2024 07:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 09:13 PM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2024 11:26 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2024 06:53 PM
Hi @CV1 ,
Restoring old emails from: ar_sys_email, you can collect their id from sys_archive_log table
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: