i heve below code to convert csv to ZIP. the CSV f...
# suitescript
v
i heve below code to convert csv to ZIP. the CSV file have 800 lines and its zipped perfectly. but when we unzip the file, it returns all the 800 lines into 1 single long line. var csvFileWOHeaders = file.create({ name : 'CSVWithoutHeaders.csv', fileType : file.Type.CSV, contents : newContents, folder : folderID, isOnline : true }); var csvFileWOHeadersID = csvFileWOHeaders.save(); var loadFile = file.load({ id : csvFileWOHeadersID }); var zippedCSV = compress.gzip({ file : loadFile, level : 9 }); zippedCSV.folder = folderID; var zippedCSVID = zippedCSV.save(); What should i do to achieve the result? pleasehlp
c
Share the code that creates
newContents
v
var contents = csvFile.getContents(); log.debug('cont',contents); var iterator = csvFile.lines.iterator(); //skip the header iterator.each(function () { return false; }); var newContents = ''; iterator.each(function (line) { newContents += line.value; return true; }); log.debug('newcont',newContents);
c
Ok, so where do you think you should look to see if there are newlines/carriage returns?
v
iterator.each(function (line) { newContents += line.value; return true; }); Here
am i right?
c
This is not something I'd expect you to know, so I'll tell you. To add a cr/nl to a string use:
str = str + "\r\n";
v
where should i use this?
iterator.each(function (line) { newContents += line.value; newContents = newContens + "\r\n" return true; });
is this how to do?
c
Use your initiative and try instead of asking?
v
Thank you , i tried it works fine