We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

We need to be able to mass restore archived records...is that possible? If so, how?

AllenTschumper
Kilo Contributor

We are moving, or already have moved to a CSM instance of service now and are soon to retire our old instance (end of year),

Now we need to move old data over from the old instance.  I want to move our archived data.  I am finding that I need to restore the RITM data to be able to retain the variables on them.  If I don't restore, things do not work as needed.  

But really, I just want to know if there is a way to mass restore archived records and NOT have to do them one-by-one.  Which the latter is no feasible with having hundreds of thousands of records.  I am assuming we'd need a script.  

Anyone able to do this?

16 REPLIES 16

okay, I did get it to work, but NOT on the sys_archive_log.list  if I go to say, sys_users (so User Admin > Users in the nav bar) I can then go to the header and have the drop down and it does show 1000, 5000 and 10000.  Great. But if I go to hat archive log list and try the same...no dice.  Doesn't work on that at all.

I did set the rows to 10000 on different lists and it takes eons to come back and thinking this may be a lost cause to do it this way 😞  sucky.  But at least can do 100 at a time until I can get some internal folks to help with a script instead to do a mass amount.  

 

Thank you. 

Not applicable

Well - that's irritating. I didn't know that the row_count was fixed on that table - you learn something new every day! 

How easy to do you think a script would be to create to be able to mass restore archived records?  Just curious if you have any ideas/thoughts on that. 

joeyfrease
Tera Expert

 

 

 

 

gs.log(“Start Restore Date and Time “+ gs.nowDateTime());

var g = new GlideRecord('ar_incident');

gr.addQuery(“sys_archived>=javascript:gs.dateGenerate('2021-10-11','09:00:00’)”);

g.query();

while (g.next()){

gs.print(g.sys_id);

 

 

var gr = new GlideRecord("sys_archive_log");

gr.addQuery("id", g.sys_id);

gr.addNotNullQuery("archive");

gr.setLimit(1);

gr.query();

 

if (gr.next()) {

new GlideArchiveRestore().restore(gr.sys_id);

 

var gr2 = new GlideRecord("sys_archive_related");

gr2.addQuery("archive_map", gr.archive);

gr2.query();

 

while (gr2.next()) {

var gr3 = new GlideRecord("sys_archive_log");

gr3.addQuery("archive_run", gr.archive_run);

gr3.query();

 

while (gr3.next())

if (gs.getXMLText(gr3.payload, "//" + gr2.element) == gr.id)

new GlideArchiveRestore().restore(gr3.sys_id);

}

 

}

 

}

 

gs.log(“End Restore Date and Time “+ gs.nowDateTime());

 

shitanshu2
Tera Contributor

Hello  Allen,

-Write Glide on "sys_archive_log" table and apply filter on non restored records to run query faster.
-Method to restore records are- > new GlideArchiveRestore().restore(gr2.sys_id);

SOLUTION->

var gr2 = new GlideRecord("sys_archive_log");
gr2.addEncodedQuery("from_table=YOUR_TABLE_NAME^restored=NULL"); //Replace table name
gr2.query();
while (gr2.next())
  {
     new GlideArchiveRestore().restore(gr2.sys_id);
   }

 

Please mark the solution correct if it answers your query. 🙂