File.lines.iterator()
Method Description |
Method used to pass the next line as an argument to a developer-defined function. You can call this method multiple times to loop over the file contents as a stream. Return This method can be used on text or .csv files.
Important:
Content held in memory is limited to 10MB. Therefore, each line must be less than 10MB. |
Returns |
boolean |
Supported Script Types |
Server scripts For more information, see SuiteScript 2.x Script Types. |
Governance |
None |
Module |
|
Since |
2017.1 |
Parameters
Parameter |
Type |
Required / Optional |
Description |
Since |
---|---|---|---|---|
lineContext |
iterator |
required |
Iterator which provides the next line of text from the text file to the iterator function. |
2017.1 |
Errors
Error Code |
Message |
Thrown If |
---|---|---|
|
The content you are attempting to access exceeds the maximum allowed size of 10 MB. |
You attempt to return the content of a line larger than 10MB. |
|
|
You call File.lines.iterator() after calling File.appendLine(options). Call File.resetStream() or save the file. |
Syntax
The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/file Module Script Samples.
//Add additional code
...
var iterator = invoiceFile.lines.iterator();
//Skip the first line (CSV header)
iterator.each(function () {return false;});
iterator.each(function (line)
{
// This function updates the total by
// adding the amount on each line to it
var lineValues = line.value.split(',');
var lineAmount = parseFloat(lineValues[1]);
if (!lineAmount)
throw error.create({
name: 'INVALID_INVOICE_FILE',
message: 'Invoice file contained non-numeric value for total: ' + lineValues[1]
});
total += lineAmount;
return true;
});
...
//Add additional code