Ways to export sys_attachment_doc table

georgechen
Kilo Guru

Hi Folks

Any idea how to back up sys_attachment_doc records on a date range?     The table list layout seems to time out every time it is being loaded, even with a simple script querying

var rec = new GlideRecord('sys_attachment_doc')

rec.addEncodedQuery("sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-02','00:24:00')@javascript:gs.dateGenerate('2015-10-02','00:54:00')");

rec.query();

if (rec.next()) {

  gs.print(rec.sys_id + '\t' + rec.sys_created_on);

}

Any idea would be appreciated.

1 ACCEPTED SOLUTION

Hi George,



Thanks for getting back with the happy ending!


Consider marking your last post, mentioning export to xml, as the correct answer.



Best Regards



Tony


View solution in original post

9 REPLIES 9

tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi George,



Did you copy the encoded query from a list view?


Does the list view time out? For all the records - or a for a date range?


How many records are there in sys_attachment_doc?


This table as you may already know contains   attachments broken into chunks - around 3 K per chunk I think.



Best Regards



Tony


Hi Tony


Yes the date range is from 2nd Oct 00:24 to 2nd Oct 10:00, and the list times out every time.


Not sure of the number of records as I am not able to view the table by list view.


Hi George,



Perhaps you could get a list of sys_attachment sys_ids for the data range you mention.


And then for each sys_attachment   get the matching sys_attachment_doc chunks?



Best Regards



Tony


Yep Yony, I have created a script to render the doc chunks



// sys_attachment table


var rec = new GlideRecord('sys_attachment')


rec.addEncodedQuery("sys_created_onBETWEENjavascript:gs.dateGenerate('2015-10-02','00:24:00')@javascript:gs.dateGenerate('2015-10-02','10:00:00')");



rec.query();



if (rec.next()) {


  while (rec.next()) {



//bind sys_attachment


    var att_doc = new GlideRecord('sys_attachment_doc')



            gs.print(rec.sys_id + '\t' + rec.sys_created_on + '\t' + rec.file_name + '\t' + rec.size_bytes + '\t' + rec.table_name);



      att_doc.addQuery('sys_attachment',rec.sys_id);


att_doc.query();


 


            if (att_doc.next()) {


              gs.print("attachment doc found");


                      while (att_doc.next()) {


                          gs.print(att_doc.sys_created_by + '\t' + att_doc.sys_created_on + '\t' + att_doc.sys_id + '\t' + att_doc.data + '\t' + att_doc.length + '\t' + att_doc.position);



                      }



              }



}


}





151008_data_chunk_sample_output_dev_on_2_october_00_54.JPG