File.lines.iterator()

Note:

The content in this help topic pertains to SuiteScript 2.0.

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 false to stop the loop. Return true to continue the loop. By default, false is returned when the end of the file is reached.

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

N/file 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

SSS_FILE_CONTENT_SIZE_EXCEEDED

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_CANNOT_READ_FROM_A_FILE_AFTER_YOU_BEGAN_WRITING_TO_IT

 

You call File.lines.iterator() after calling File.appendLine(options). Call File.resetStream() or save the file.

Syntax
Important:

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 

        

Related Topics

file.File
N/file Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices