How to convert .txt file to .zip file using script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2014 07:54 AM
Hi,
I have an issue while converting a .txt file to .zip file through script. Actual, requirement is "whenever .txt file is attached to a ticket, we need to convert that .txt file to .zip file."
For that , i have created a on BR on sys_attachment table with the following code:
var zipName = fileName +'.zip';
try{
var FileName = current.file_name;
var zFile = new Packages.java.io.File(zipName);
var outStream = new Packages.java.io.FileOutputStream(zFile);
var out = new Packages.java.util.zip.ZipOutputStream(outStream);
var sa = new Packages.com.glide.ui.SysAttachment();
//var sa = new GlideSysAttachment();
var binData = sa.getBytes(current);
addBytesToZip(out, zipName, FileName, binData);
gr.content_type = "application/octet-stream";
gr.file_name = zipName;
gr.update();
}
catch(Exception)
{
gs.log("**Exception:"+Exception);
}
function addBytesToZip (out, dir, Filename, stream)
{
out.putNextEntry(new Packages.java.util.zip.ZipEntry(Filename));
out.write(stream, 0, stream.length);
out.closeEntry();
}
During the execution, i am getting an exception as "TypeError: [JavaPackage java.io.FileOutputStream] is not a function." and is for the line
var outStream = new Packages.java.io.FileOutputStream(zFile);
Please help me to resolve the error and to convert the file to .zip file.
Thanks in advance,
Prasanna

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2014 08:05 AM