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

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.


Thanks man.   Sometimes things need to be spoonfed     I truly appreciate it.
Here is a screenshot of the success.   Thanks!


attachment_success.png


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

A few months ago, this got me where I needed to get, though I still had a hurdle of obtaining the sys_id for the many thousands of records that we need to attach files to.   In working through this, I developed out a process utilizing POWERSHELL that allows the fully automated attachment of files to records across multiple tables.   You can check it out at the link below.

https://community.servicenow.com/docs/DOC-3781


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

Hi Travis, i am new to REST in servicenow...I need to send an attachment along with some other details from a table


I figured   out how to send the fields but how will i send the attachment from that record if any ? any suggestions?




var gr = new GlideRecord("sys_user");


gr.query();


while (gr.next()){


  var request = new sn_ws.RESTMessageV2();


  request.setEndpoint('https://myendpoint/now/v1/import/table');


  request.setHttpMethod('post');


  var user = 'my_User';


  var password = 'mypassword';



  request.setBasicAuth(user,password);


  request.setRequestHeader("Accept","application/json");


  request.setRequestHeader('Content-Type','application/json');



  var reqBody = "{'u_active':'" + gr.active + "','u_ad_id':'" + gr.u_ad_id + "','u_business_phone':'" + gr.phone + "','u_city':'" + gr.city + "','u_country':'" ,


  + gr.u_top_level_org_unit + "','u_user_id':'" + gr.user_name + "','u_zip_postal_code':'" + gr.zip + "'}";


  request.setRequestBody(reqBody);



  var response = request.execute();


 


}


Hi Matthew,



This is the process I have used to send attachments for a long while: Generate Attachments in ServiceNow via REST-John Andersen .   There may be a newer/better way but I haven't looked into it in a while.   Basically, you will:



1.   Create the record over REST and hold onto the table / sys_id of the created record in variables


2.   Base64 encode the attachment and send it to the ecc_queue table via REST with the record (table / sys_id) to attach to


3.   Repeat step 2 for any additional attachments



Make sure to log success/failure if you are doing batch or recurring calls like this... the last thing you want is to drop information and not be aware of it.



Kind regards,



Travis