"Download all attachments in a single zip file" customization is creating issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2015 06:09 AM
Hello,
I have tried to configure a ui action to download all attachments in a single zip file.
I have taken help from servicenowguru : Download Attachments as a ZIP File - ServiceNow Guru
I am able to download the attachments in a single zip file but it is breaking some system functionalities (even for admins), such as :
- Not able to personalize list of records through List mechanic. The slushbucket is not showing any field as available to add/remove.
- Not able to open any workflow.
- "Reset to column defaults" is not appearing through List mechanic.
- on right click on any field it is not showing proper context menu.
- not able to modify any data from list of records.
UI Action :
- Show Insert , Show Update, Client : TRUE
- Table : Task
- Onclick : saveAttachmentsToZip();
- Condition : current.hasAttachments();
//action.setRedirectURL('saveAttachmentsToZip.do?sysparm_sys_id=' + current.sys_id + '&sysparm_table=' + current.getTableName());
//action.setRedirectURL('sys_attachment.do?sys_id=' + current.sys_id + '&table_name=' + current.getTableName());
function saveAttachmentsToZip() {
var url = new GlideURL('saveAttachmentsToZip.do');
url.addParam('sysparm_sys_id', g_form.getUniqueValue()); //gel("sys_uniqueValue").value
url.addParam('sysparm_table', g_form.getTableName());
var frame = top.gsft_main;
if (!frame)
frame = top;
frame.location = url.getURL();
}
I have tried only action.setRedirectURL (Line 1)...but facing same issue.
Processor :
- Type : Script
- Application Scope : Global
- Parameters : sysparm_sys_id,sysparm_table [As expected, without parameters the ui action is not working]
- Path : saveAttachmentsToZip
var sysid = g_request.getParameter('sysparm_sys_id');
var table = g_request.getParameter('sysparm_table');
var theRecord = new GlideRecord(table);
theRecord.addQuery('sys_id', sysid);
theRecord.query();
theRecord.next();
var zipName = 'attachments.zip';
var StringUtil = GlideStringUtil;
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', theRecord.sys_id);
gr.addQuery('table_name', theRecord.getTableName());
gr.query();
if (gr.hasNext()){
g_response.setHeader('Pragma', 'public');
g_response.addHeader('Cache-Control', 'max-age=0');
g_response.setContentType('application/octet-stream');
g_response.addHeader('Content-Disposition', 'attachment;filename=' + zipName);
//var out = new Packages.java.util.zip.ZipOutputStream(g_response.getOutputStream());
var out = GlideZipOutputStream(g_response.getOutputStream());
//var count=0;
while (gr.next()){
var sa = new GlideSysAttachment();
//var binData = sa.getBytes(gr);
var binData = sa.getContent(gr); /* getContent is limited to 5mb */
var file = gr.file_name;
this.addBytesToZip(out, zipName, file, binData);
//count ++;
}
// Complete the ZIP file
out.close();
}
function addBytesToZip (out, dir, file, stream){
// Add ZIP entry to output stream.
//out.putNextEntry(new Packages.java.util.zip.ZipEntry(file));
out.putNextEntry(new GlideZipEntry(file));
out.write(stream, 0, stream.length);
out.closeEntry();
}
Issue snapshot :
Once I am deactivating the processor, the issue is not there. Hence, the issue is causing due to the custom processor.
Please help me to rectify the issue.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2015 06:36 AM
The customization is done on an instance which is having build version as 'Fuji - Patch 4'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2015 02:38 PM
I've tried using that SNGuru solution and it works great. Here is a record in demo022 (Fuji) where I've applied the solution and it's working there, too.
https://demo022.service-now.com/nav_to.do?uri=incident.do?sys_id=d71f7935c0a8016700802b64c67c11c6
The processor would have nothing to do with your problem. What you're seeing is a common problem when you have a syntax error in a client script. I'd double-check your UI Action as it is running client-side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2015 01:12 AM
Hello Jacob,
The solution is working perfectly fine, I am able to download attachments in zip file but it is conflicting with some of the system functionality (I guess) and giving me issues.
Note : To troubleshoot the issue, I just configured the processor, even didn't configure the UI Action.
Following are the issues with the processor (Script used : As shared in the post):
1. Not able to modify the filter in list of records (On click the filter button, its not showing the filter options)
Able to see filters once the processor is inactive -
2. Not able to add/remove fields in list of records through list mechanic once the processor is active.
"Reset to column defaults" is not appearing too.
3. Workflow issue :
While the processor is active, system is not able to render workflow :
When the processor is inactive,
4. Not able to edit any field from list of record, when the processor is active.
Giving error as : No response from server - try again later
FYI : I have also raised a 'hi' ticket for the issue but they are not able to help me and I had to close the ticket as they asked me to take help from their professional service as it is a customization. Their dev team kept the ticket on hold for long time to look into the issue thoroughly but no luck!
Warm Regards,
Subhankar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2015 01:16 AM
I also got a chance to test the customization in a dublin build instance but noticed the same issues.