How to open a URL via background script or download large amount of attachments from multiple records via script

Daymond Krueger
Tera Contributor

I have a need to download the attachment from approximately 1000 records that are on a table.  I can do a query to sys_attachment in a background script to return these records, but I am unable to find a way to either "open" this records via script (which downloads the attachment) or any other method that will allow me to download the attachment (PDF files) from all of these records via script.  Anyone have any ideas?

4 REPLIES 4

Jake Sadler
Kilo Sage

Hi,

 

This article should answer your question:

 

https://servicenowguru.com/scripting/download-attachments-zip-file/

 

Thanks

 

Jake

Daymond Krueger
Tera Contributor

Thanks Jake, but I need a method that will do it automatically via script without going into each record and clicking a UI action.

Hi,

 

Perhaps you can look at modifying the script they've suggested or put in a while loop to loop over the attachments table.

 

Thanks

 

Jake

-O-
Kilo Patron
Kilo Patron

You need to write a script in some computer scripting language, like PowerShell, or Bash, or Python, or whatever. Cause servers can't push to clients things that the client does not request or agree to receive. If clients did that, the web would be the most insecure dangerous place there could be.

Go to REST API Explorer in your instance, look up the "Attachment API" API Name under the "now" Namespace and there you will find examples on how to download files for several scripting languages. If you need data on what to download, you could bake that into your script by visiting the "Table API" API Name under the same "now" Namespace and looking at the examples for your favorite scripting language.