i want to remove the header line from the csv file...
# suitescript
v
i want to remove the header line from the csv file? how to do that?
a
Copy code
let fileObj = file.load({id: fileId});
const iterator = fileObj.lines.iterator();

//skip the header
iterator.each(function () {
    return false;
});

let newContents = '';
iterator.each(function (line) {
    newContents += line.value;
});
log.debug(newContents);
n
Copy code
const removeHeaderLine = (csv) => {
  const lines = csv.split('\n');
  lines.shift();
  return lines.join('\n');
}
oh i like anthony's better
😂 1
a
I mean they're both fine
n
Also this is the perfect type of question to ask chatGPT. May speed up your process a little if you don't want to wait for a response here
Although looking at what it wrote maybe not. Its weird that it joined the string the separated it again to return
e
It's also assigning the NS file module to the file variable
sadblob 1
n
Ok ignore everything i said. +1 for humans, -1 for robots
😂 2
n
My bot replied:
n
Yeah it has the same problem that ehcanadian mentioned. Your file module is likely aliased as file. Then you are overwriting it by storing the loaded csv as var file So as long as you updated your file variable that would work fine
n
It's an assumption and in the wrong hands yeah totally a risk
💯 1
v
actually i was exporting the saved search to a csv file and saved in the file cabinet prior. now the customer wants to save it as a zip file. so now 1. export saved search to CSV 2. Load the CSV to remove the header 3. and convert into ZIP 4. and save it in file cabinet Now my question is how to remove the header wthout saving the csv into the file cabinet because which is again saving into the file cabinet the customer dont want
a
save csv into the file cabinet anyway remove the line as before convert to zip save zip to the file cabinet delete the csv from the file cabinet
v
i get the iterator as {} empty.
I need to load the CSV after saving the search results. but it shows empty when i am loading i mean the process is not completed when i load the CSV. what could i do?
e
Use the addInboundDependency method.