Restore deleted references to deleted records - Not Audited Table

sachin_namjoshi
Kilo Patron
Kilo Patron

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

5 REPLIES 5

haseena ayesha
Kilo Guru

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


http://wiki.servicenow.com/index.php?title=Creating_Custom_Applications#Restoring_Deleted_Records&gs...




Thanks & Regards


Haseena


                                                                  PS: Hit like, Helpful or Correct depending on the impact of the response


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);


  1. brokenRecord.addNullQuery(fieldName); // No use processing records where there is still an AG
  2. 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


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.


Joel Dias
Kilo Sage

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.


Export and import XML files



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.