How to open a URL via background script or download large amount of attachments from multiple records via script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 07:59 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 08:01 AM
Hi,
This article should answer your question:
https://servicenowguru.com/scripting/download-attachments-zip-file/
Thanks
Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 08:55 AM
Thanks Jake, but I need a method that will do it automatically via script without going into each record and clicking a UI action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 09:24 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2022 10:04 AM
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.