Create record csv along with related tables

shivani46
Tera Contributor

I have one requirement .
I want to fetch all the table record along with related tables(sys audit, history, attachment etc)
In csv file.
Anyone have any solution or have done this kind of requirement.

3 REPLIES 3

Rub_n Ruiz Tris
Tera Contributor

Hi Shivani46,

 

The answer depends a bit on what exactly you need to achieve, as the post does not include much detail about the use case.

For example, the right approach may be different depending on whether this is:

  • a one-time data extract,
  • a recurring integration,
  • a migration to another instance or system,
  • a reporting requirement,
  • or an archival/compliance requirement.

It also matters which “related tables” you mean: child task records, journal entries, audit/history data, approvals, attachments, custom related lists, etc.

That said, I would not recommend trying to export the main records, related records, audit/history, and attachments into a single CSV.

CSV is a flat format, while ServiceNow data is relational and attachments should be handled separately. They cannot practically be included inside a normal CSV export.

sys_attachment contains metadata, while the actual attachment content needs to be downloaded separately, usually through the Attachment API or a controlled scripted process.

 

A cleaner approach would be to export the data as a package of related files, for example:

  • parent_table.csv
  • child_or_related_table.csv
  • sys_audit.csv, if audit history is required.
  • sys_journal_field.csv, if comments/work notes are required.
  • sys_attachment.csv, for attachment metadata.
  • attachment files downloaded separately.

The important part is to preserve the relationship between the files using keys such as the parent record sys_id, reference fields on the related records, etc.

 

For audit/history, I would also be careful. Exporting sys_audit without tight filters can create a very large extract. You should filter by table, record sys_id, date range and only the fields that are actually needed.

 

For a one-time export, I would normally look at Export Sets or a controlled scripted export.

For a migration scenario, I would also consider whether the target system needs the original sys_id values or only business keys.

 

So, yes, this can be done, but I would first clarify the exact requirement and then design it as a multi-file export with clear relationships, rather than trying to flatten everything into one CSV.


Hope that Helps!

Please mark this response correct by clicking on "Accept as Solution" and/or mark it as "Helpful" (kudos) if it helps. 

Ankur Bawiskar
Tera Patron

@shivani46 

what's your actual business requirement for this?

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

My bossiness requirement is want to build a scalable servicenow export framework that can export huge volume of data record (lakhs/million) along with all related table data, audit history, approval, variables etc. Into CSV file and generated a final zip.

 

like if i have 1lakh of incident record then one incident.csv.

all the related tables which have records.

like approval.csv, sla.csv etc.

then all the csv should be in one zip file.