How to export incident attachments

bhadra
Kilo Explorer

Hi All,

 

Could you share how to export / extract all the attachments from incident, problem and change tickets.

 

Thanks

5 REPLIES 5

James_Neale
Mega Guru

Attachment records are in the sys_attachment table with the data chunked and stored in a separate table. As far as I know there is no built in mechanism to bulk export attachments, though there are various ways to download individual attachments.



ServiceNow have a built in processor that sends the file when you call the attachment table, e.g: /sys_attachment.do?sys_id=abc123... will, depending on the file type and your browser settings, download or display the attachment. If you click on a sys_attachment record to open it, it will actually download the file.


You might be able to use this in conjunction with a web service to the attachment table to query all the attachment records where table = incident/problem/change and then make an HTTP GET to sys_attachment using the sys_id to download the file. Obviously you would have to do this on a local server and ensure you store the document key for each attachment as well so you know where it came. You would also have to account for the max result limitations.



I can understand downloading a few attachments, but why all of them? Attachments aren't going to be that useful without the context of the ticket.


- James


Hi James,



Thanks a lot for the info. Requirement is to extract all the attachments along with Incident / problem / Change ticket number via web-service. I am planning to automate webservice to download all the attachment along with references (ie., ticket number)



I would like to share my approach.



1. In ServiceNow, export incident details such as Incident no | short description | Other columns


2. Automate webservice (i.e, loop through Incident ticket numbers) - Input is Incident number


      Output - Filename



3. download attachments to specific folder



Final output would be


Incident no | filename | file location (path)



I explored in different ways and ended up at little success. Could you share how to convert xml output to image file



https://demoodbc.service-now.com/IncidentAttachments.do?incident=INC0014956


I'm not certain on the storage mechanism but I'm pretty sure it's Base64, unless just writing the data and giving it a filename ending in .jpg or whatever works. You can probably find a fair number of B64 decoding examples with a quick search.


- James


Hi Bhadra,



Did you get a solution for this? Even we are looking the same. If you have found solution could you please share with us also