Download Attachment To MID Server

amkatulak
Giga Expert

Hello,

Does anyone know of a good way to have a MID Server download an attachment stored in ServiceNow?   Here's my scenario:

1.   User uploads a CSV file to ServiceNow via a Service Catalog Request

2.   Workflow runs that executes a powershell script on the MID Server.  

        a.   Powershell script attempts to download the csv file from the sys_attachment table using the WebClient.Download method.   My script utilizes a GlideRecord lookup to find the attachment, and creates a URI like <instance_URI>sys_attachment.do?sys_id=c782c2f1e8c92100b7cb5d8ce68ba9ce to identify the file to download.

        b.   This actually downloads a file, but it's not the attachment that it should be (even though copying and pasting this exact URI in a browser produces the correct file)  

        c.   Once the attachment is downloaded, I have additional powershell functions that should run against the data in the CSV, but since the file is not downloaded properly, this is where I error out.  

 

Any help is appreciated!

Thanks

1 ACCEPTED SOLUTION

Jacob_Andersen
ServiceNow Employee
ServiceNow Employee

Adam,



A simple way to handle this is to create a processor in ServiceNow that takes the table and sys_id of the record as input parameters.   Then export the attachments to that record as a zip file and download.  



I wrote a solution to do this several years ago here:   » Download Attachments as a ZIP File



The only difference in your scenario than what is in my post is that you won't need the UI action that builds the URL. Simply use that same URL in your powershell script and you should be good.



Hopefully this helps.


View solution in original post

2 REPLIES 2

Jacob_Andersen
ServiceNow Employee
ServiceNow Employee

Adam,



A simple way to handle this is to create a processor in ServiceNow that takes the table and sys_id of the record as input parameters.   Then export the attachments to that record as a zip file and download.  



I wrote a solution to do this several years ago here:   » Download Attachments as a ZIP File



The only difference in your scenario than what is in my post is that you won't need the UI action that builds the URL. Simply use that same URL in your powershell script and you should be good.



Hopefully this helps.


Vivek Kumar9
Tera Contributor

Hi Adam,


we also having the same type of requirement, we need to put the attachments in sftp server via midserver.


could you please help me with code what you have used to achieve this