Export of all KBAs that include any attachments

srashtis
Tera Contributor

Hi All,

 

How can we export bulk KBAs, including any attachments associated with the articles? We want the export to be used for importing into a different tool.

 

Thank you in advance for your help.

1 REPLY 1

pratikjagtap
Giga Guru

Hi @srashtis ,

 

Export KB Articles (KBAs)
Option 1: Using ServiceNow Export Functionality (CSV/XML)
Navigate to Knowledge > Articles.

Apply any necessary filters (e.g., based on published articles, categories).

Click the List Actions (hamburger menu) > Export.

Choose CSV or XML format.

CSV: Good for text-based exports but does not include attachments.

XML: More structured and can preserve references to attachments.

2. Export Attachments Associated with KBAs
Since ServiceNow does not include attachments in a standard CSV/XML export, you need to retrieve them separately.

Option 1: Scripted Approach (Best for Large Exports)
Use a Scripted REST API or Scheduled Script to:

Query all attachments linked to KBAs from the sys_attachment and sys_attachment_doc tables.

Download attachments as files.

Store them in a ZIP archive or a location where the new tool can access them.

Sample Script to Download Attachments:

   

var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addQuery('table_name', 'kb_knowledge'); // Filter for KB articles
grAttachment.query();

while (grAttachment.next()) {
var attachmentID = grAttachment.sys_id;
var fileName = grAttachment.file_name;
var fileData = new GlideSysAttachment().getContent(grAttachment);

gs.info("Attachment Name: " + fileName + ", Data Size: " + fileData.length);

// Save or export the file (modify as per need)
}

 

 

  • This script retrieves attachment metadata and file data.

  • Modify it to save attachments to an external location or ZIP file.

3.Import into the New Tool
Once you have:

Articles in CSV/XML format

Attachments exported separately

Check if the target system supports:

Direct import of XML (if it retains relationships).

CSV with attachment paths (if attachments need to be manually linked post-import).

Alternative: Use ServiceNow's Out-of-the-Box Integration
If the target system supports integrations, you can explore:

ServiceNow REST API to fetch articles and attachments programmatically.

Data Export via Integration Hub (if the new tool has an integration).

 

If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍 !

 

Regards,

Pratik