Download Attachments via Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 06:10 PM
Hi,
I have been working on a script to export several attachments from Incidents. Using loops I can get the Incidents and attachment records just fine, I simply cannot get them exported.
I tried using a MID Server script but I was unable to figure out how to properly set up the data set,
Scripting looked like it was going to be easy but I have fiddled with this for 4 or 5 hours now. Where I seem to be stuck is getting my output stream properly defined. I have used these two articles for reference:
https://community.servicenow.com/community?id=community_question&sys_id=e225af43db6f67844abd5583ca961959&view_source=searchResult
https://www.servicenowguru.com/scripting/download-attachments-zip-file/#comment-34336
For the most part, pretty helpful. I have tried this from Script Includes, UI Action, FIX Scripts and Background scripts. I currently have a Script Include with what I consider a pretty good definition. This is specifically where I'm tied up. As far as the articles state, use g_response to build the output stream. I get an undefined from this code line:
var out = new Packages.java.util.zip.ZipOutputStream(g_response.getOutputStream());
I have tried passing in the variable from the UI Action, Background Script, FIX Script, etc. I also defined the variable in the Script Include such as:
var thisResponse;
thisResponse.setHeader('Pragma', 'public');
thisResponse.addHeader('Cache-Control', 'max-age=0');
thisResponse.addHeader('Content-Disposition', 'attachment;filename=' + zipName);
thisResponse.setContentType('application/octet-stream');
var out = new Packages.java.util.zip.ZipOutputStream(thisResponse.getOutputStream());
No matter the variable I use or pass in to the Function for "thisResponse.getOutputStream()", I get undefined.
I'm, sure I'm missing something silly, I just don't know what it is.
Thanks you for your support,
Art Anderson
- Labels:
-
Managed Documents
-
MID Server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2022 05:59 AM
Hi Madhu,
We never did find a way to export from ServiceNow to a user's desktop other than the internal attachments link on individual records. We were able to successfully download to MID servers (which we have done for quite some time) but simply not to an end user desktop. We have since closed our internal customer request as not feasible at this time.
Thanks,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2022 11:42 AM
Hello i want to download attachment in any folder with using mid server.