Has anyone successfully imported multiple files as attachments to multiple records?

John VanBruggen
Giga Guru

I have a need to upload a large number of attachments that were exported from another system.

The files will be attached to the records that they were tied to in the previous system.

I have found the following articles

* http://wiki.service-now.com/index.php?title=AttachmentCreator_SOAP_Web_Service
*
http://www.servicenowguru.com/integration/sending-attachment-servicenow/

These solutions are for either loading a single file or loading multiple files to a single record.

Has anyone had any luck with loading many files to many records?  

I would be interested in hearing what you used to accomplish this.  

Thanks!

Check out my Consultant's Survival Guide
https://youtube.com/watch?v=zYi8KhP9SUk
1 ACCEPTED SOLUTION

Sounds good.   This might seem a little silly, but we are actually using pretty much the same general process as the SOAP messages above or John Andersen's REST method Send Attachments using REST... that is we are going to Import the attachments into the ECC Queue.   Except we will be doing it without needing to connect to a web service end point.   Here's the Transform Map info:



Transform Map Record


      Name: <whatever you want to name it>


      Source table: <your imported source table created from the csv>


      Target table: Queue [ecc_queue]


      The rest should be left as defaults



Mapped Fields


        Static Fields that are the same for every record imported


        agent: "AttachmentCreator"


        topic: "AttachmentCreator"



        Fields that need to be included in your csv or determined via script


        name: "[FILENAME]:[MIME_TYPE_FOR_FILENAME]"


        source: "[TABLE_NAME]:[SYS_ID_OF_RECORD_TO_ATTACH_TO]"


        payload: "[INSERT_BASE64_STRING_HERE]"



This means that your csv file MUST include:


        Filename


        Table Name of the record to which the attachment is attached


        Sys Id of the record to which the attachment is attached


        Base64 encoded string of the data for the attachment



The Mime type, you can either script by looking at the extension of the filename OR you can add a field to your csv and keep the import set simple.



Once the import set drops these records into the ECC Queue, the Attachment Creator (built into the ServiceNow out of 'box') will handle the rest.


View solution in original post

18 REPLIES 18

tltoulson
Kilo Sage

Hi John,



If you are exporting from one ServiceNow Instance to Import into another, here is an approach I have used in the past:



1.   In the source system, navigate to sys_attachment.list and export the records as XML


2.   In the source system, navigate to sys_attachment_doc.list and filter where sys_attachment matches any of the attachments exported previously


3.   Export the filtered sys_attachment_doc records as XML


4.   In the destination system, import the sys_attachment XML


5.   In the destination system, import the sys_attachment_doc XML



I am not sure if this will work on all doc types but so far, I have never encountered an issue.   Keep in mind, the records that possess the attachments need to exist in both systems and the sys_ids must be the same for this to work.


Travis,


I wish it were this simple.   The files are not coming from another instance.   They will be on a LAN drive that we will be importing from.



Thanks!


Check out my Consultant's Survival Guide
https://youtube.com/watch?v=zYi8KhP9SUk

Hello,

Thanks for the great information here. Just a question on the part of the Base64 string. Can you give an example or steps if I wanted to convert a PDF file to a base64 string?

Thanks.

Matt Saxton - G
Kilo Guru

John,



It would be helpful is you told us a little more about these attachments.   (where are they stored? Another Instance? A DB? A File system?)



I did something a little more complex when converting over RKM documents once. I have posted my process here Conversion: Remedy Knowledge 7.5 to ServiceNOW Knowledge Management.



Good Luck!