How to fix getBytes Error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
Hi All,
in Scoped - SCript Include :
var fileList=[];
var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', '1fabd08cf01a483faf9fa7e67bc0b4b7');
att.addQuery('file_name', 'ENDSWITH', 'abc.pdf');
att.query();
if (att.next()) {
fileList.push({
name: att.file_name.toString(),
bytes: new GlideSysAttachment().getContent(att)
});
}
var zipUtil = new GlobalZipUtil();
var zipBytes = zipUtil.createZip(files);
gs.info("zipBytes :"+JSON.stringify(zipBytes));
Global SCript Include:
n Global SCript Include :
var GlobalZipUtil = Class.create();
GlobalZipUtil.prototype = {
initialize: function() {},
createZip: function(files) {
// files = [{name: 'x.pdf', bytes: [...]}, ...]
var outStream = new Packages.java.io.ByteArrayOutputStream();
var zip = new Packages.java.util.zip.ZipOutputStream(outStream);
for (var i = 0; i < files.length; i++) {
var entry = new Packages.java.util.zip.ZipEntry(files[i].name);
zip.putNextEntry(entry);
zip.write(files[i].bytes, 0, files[i].bytes.length);
zip.closeEntry();
}
zip.close();
return outStream.toByteArray();
},
type: 'GlobalZipUtil'
};
zip.write(files[i].bytes, 0, files[i].bytes.length); we are getting Error here
zip.write(files[i].bytes, 0, files[i].bytes.length); getting error like can't find method ava.util.zip.ZipOutputStream(string,number,number)
How to fix it please, we are calling "Client Callable Script Include " in UI Action (client=true).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hello @Supriya25,
@Allen Andreas posted a very detailed write up on How to download all attachments from a record to a Zip file. I would highly suggest reading through this to see if there is a more efficient way to accomplish the same goal.
If you don't find this solution helpful and want to continue on the current path, could you post some screenshots of the actual errors you are seeing?
Sr. ServiceNow Developer | Infosys