Restore deleted references to deleted records - Not Audited Table

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 09:46 PM
Hello All,
Please help in resolving below issue.
I have reference field on custom table. This reference field is pointing to cmn_cost_center table.
By mistake, system admin deleted all records from cmn_cost_center table.Hence, all reference field reference values ( pointing to cmn_cost_center) on custom table are gone.
cmn_cost_center table is NOT audited OOB.Hence, i can't restore deleted records for cmn_cost_center table.
1. How can i retrive deleted records from cmn_cost_center table?
2. How can i restore deleted references to deleted records on custom table?
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 09:59 PM
Hi
Sachin,
Please check these links it may be helpful to you,
http://wiki.servicenow.com/index.php?title=Restoring_Deleted_Records#gsc.tab=0
Thanks & Regards
Haseena
PS: Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 10:07 PM
Hi,
Restoring deleted records can not restore references.
Also, i can't use sys_audit since i won't get old values in sys_audit table for NON audited table.
Below fix script works only for audited table.
restoreReferences();
function restoreReferences(tableName, fieldName){
var brokenRecord = new GlideRecord(tableName);
- brokenRecord.addNullQuery(fieldName); // No use processing records where there is still an AG
- brokenRecord.query();
while(brokenRecord.next()){
var lastFieldValue = new GlideRecord('sys_audit');
lastFieldValue.addQuery('documentkey', brokenRecord.sys_id);
lastFieldValue.addQuery('fieldname', fieldName);
lastFieldValue.orderByDesc('sys_created_on');
lastFieldValue.query();
if(lastFieldValue.next()){
brokenRecord.setValue(fieldName, lastFieldValue.newvalue);
brokenRecord.update();
}
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 03:58 AM
are you sure that the script works? as I can check after the record has been deleted oldvalue as well as newvalue in sys_audit table is DELETED.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 11:21 PM
If the cmn_cost_center records are still available on a different instance, you can try to export/import as XML to the instance where the records are missing.
The cmn_cost_center records will keep the original sys_id. With the cmn_cost_center records back, the references on your custom table should display again.