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

Thanks Travis


Hi John,



I recommend it by the use of MID Server, as by this you can have track over each and every file from your SN and you will not be dependent on another system.


My approach has 2 parts,


1) Encode all the files in base64 payload using mid server script include and put them into a separate folder (name payload)


2) Use data source/custom mid server script to read all the payload data and put it into attachment creator web service.



Hope this will help,



--


Cheers,


AR


Hi Akash,



Can you give a little more details about your suggestion to John?   I have done this with Node.js running on a dedicated workstation that was batch uploading decrypted files,   however we are looking for something that can be accomplished on the MID directly without having to run Node.js.



In my new use case, I have a folder on a MID server where files will get dropped.   The naming convention of the files will be something like:   <table_name>-<target_record_sys_id>-<original_file_name>-<original_file_extention> e.g. incident-fd3e47a537d5268093932863b3990ed3-Weekly Status Meeting_V2.doc



Can you provide any more info for the following:


1) Encode all the files in base64 payload using mid server script include and put them into a separate folder (name payload)


2) Use data source/custom mid server script to read all the payload data and put it into attachment creator web service.



I found a MID Server Script Include called "CopyAttachments" but not sure how to call it or how to set the midServerTempPath, fileName and destination directory.



Thanks,



-e


bernyalvarado
Mega Sage

Hi John,



The solution described on the wiki that you shared actually comprehends the ability to add the attachments to multiple records. For each attachment, you just need to make 1 SOAP call where you set the corresponding file name with its appropriate content-type and the respective table and the sys_id of the record where you want to attach the file.



Thanks,


Berny