RE: Get CSV line number/count through N/file

Is there any way to get the current line number in the iterator or the total line count of a CSV through N/file? I don’t see anything about these in the documentation, but the undocumented File.lines property makes me wonder if there’s a hidden property I can read.

If this isn’t possible through N/file, is there a workaround?

adavies Rookie Asked on October 22, 2019 in SuiteScript.
Add Comment
1 Answers

I would think just doing something similar to the following should give you what you need:

var lineCount = 0;
var iterator = fileObj.lines.iterator();
// Skip the first line (CSV header)
iterator.each(function () {
    lineCount++;
    return false;
});
iterator.each(function () {
    lineCount++;
    return true;
});
Intermediate Answered on October 22, 2019.
Add Comment