GlideSysAttachment().getBytes() is not working if size of attachment is more than 5 MB?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2020 09:15 AM
I have the below code written in the processor, can you please help in providing the solution so that attachments greater than 5MB also gets downloaded. Can you please provide the exact line of code change to be done. Thank you in advance.
(function process(g_request, g_response, g_processor) {
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 count=0;
while (gr.next()){
var sa = new GlideSysAttachment();
var binData = sa.getBytes(gr);
var file = gr.file_name;
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.write(stream, 0, stream.length);
out.closeEntry();
}
})(g_request, g_response, g_processor);
I have seen posts mentioning about below :
https://community.servicenow.com/community?id=community_question&sys_id=ae11d7e9dbdcdbc01dcaf3231f961940
https://community.servicenow.com/community?id=community_question&sys_id=648a4be9db5cdbc01dcaf3231f961904
But , can I get the exact code change to be done for this. Please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2020 01:17 PM
Check the following page. Increase system properties "Maximum file attachment size in megabytes" from "System Properties" > "Security" page.
https://hi.service-now.com/kb_view.do?sysparm_article=KB0718101
