- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2016 10:45 PM
i have a requirement in which i have a UI action on my table , so when ever i click on that button i will get (form pdf + activity pdf + all attachment) into a one zip file that might be downloadable
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2016 03:58 AM
first create a ui action that attach (export to pdf) form pdf in your attachment and call processor
****************************************
var rm = new sn_ws.RESTMessageV2();
rm.setHttpMethod('GET');
var url = gs.getProperty("glide.servlet.uri") + current.getTableName()+ '.do?PDF&sys_id=' + current.sys_id;
rm.setEndpoint(url);
rm.setBasicAuth(gs.getProperty('glide.user.userid'), gs.getProperty('glide.user.password'));
rm.saveResponseBodyAsAttachment(current.getTableName(),current.sys_id,current.number+".pdf");
var response = rm.execute();
action.setRedirectURL('exportAttachmentsToZip.do?sysparm_sys_id=' + current.sys_id + '&sysparm_table=' + current.getTableName() + '&sysparm_num=' + current.number);
*******************************************
create a new processor "exportAttachmentsToZip"
************************************************************
var sysid = g_request.getParameter('sysparm_sys_id');
var table = g_request.getParameter('sysparm_table');
var num = g_request.getParameter('sysparm_num');
//var url = table + '.do?PDF&sys_id=' + sysid;
//window.open(url);
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 count=0;
while (gr.next()){
var sa = new GlideSysAttachment();
var binData = sa.getBytes(gr);
var file = gr.file_name;
this.addBytesToZip(out, zipName, file, binData);
count ++;
}
// Complete the ZIP file
out.close();
var gr1 = new GlideRecord('sys_attachment');
gr1.addQuery('table_sys_id', theRecord.sys_id);
gr1.addQuery('table_name', theRecord.getTableName());
gr1.addQuery('file_name', num+'.pdf');
gr1.query();
if(gr1.next())
gr1.deleteRecord();
}
function addBytesToZip (out, dir, file, stream){
// Add ZIP entry to output stream.
out.putNextEntry(new Packages.java.util.zip.ZipEntry(file));
out.write(stream, 0, stream.length);
out.closeEntry();
}
thats work fine . Plz remember user(userid,pass) must have admin role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2016 03:58 AM
first create a ui action that attach (export to pdf) form pdf in your attachment and call processor
****************************************
var rm = new sn_ws.RESTMessageV2();
rm.setHttpMethod('GET');
var url = gs.getProperty("glide.servlet.uri") + current.getTableName()+ '.do?PDF&sys_id=' + current.sys_id;
rm.setEndpoint(url);
rm.setBasicAuth(gs.getProperty('glide.user.userid'), gs.getProperty('glide.user.password'));
rm.saveResponseBodyAsAttachment(current.getTableName(),current.sys_id,current.number+".pdf");
var response = rm.execute();
action.setRedirectURL('exportAttachmentsToZip.do?sysparm_sys_id=' + current.sys_id + '&sysparm_table=' + current.getTableName() + '&sysparm_num=' + current.number);
*******************************************
create a new processor "exportAttachmentsToZip"
************************************************************
var sysid = g_request.getParameter('sysparm_sys_id');
var table = g_request.getParameter('sysparm_table');
var num = g_request.getParameter('sysparm_num');
//var url = table + '.do?PDF&sys_id=' + sysid;
//window.open(url);
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 count=0;
while (gr.next()){
var sa = new GlideSysAttachment();
var binData = sa.getBytes(gr);
var file = gr.file_name;
this.addBytesToZip(out, zipName, file, binData);
count ++;
}
// Complete the ZIP file
out.close();
var gr1 = new GlideRecord('sys_attachment');
gr1.addQuery('table_sys_id', theRecord.sys_id);
gr1.addQuery('table_name', theRecord.getTableName());
gr1.addQuery('file_name', num+'.pdf');
gr1.query();
if(gr1.next())
gr1.deleteRecord();
}
function addBytesToZip (out, dir, file, stream){
// Add ZIP entry to output stream.
out.putNextEntry(new Packages.java.util.zip.ZipEntry(file));
out.write(stream, 0, stream.length);
out.closeEntry();
}
thats work fine . Plz remember user(userid,pass) must have admin role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2017 04:03 AM
"Save all attachments" button does not download all the attachments
1. If you select the "Save All Attachments" ui action and unzip the folder, only 2 out of the 6 *.nmf files have downloaded. Four of them have not as they are 0KB. I have done this over 5 times, closing and opening my Chrome browser and it is reproducible each time.
2. However, if you select to download them all one by one - its successful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 11:17 AM
Does it work with smaller attachments?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 03:35 AM