documentCapture.documentToStructure(options)

Note:

The content in this help topic pertains to SuiteScript 2.1.

Method Description

Extracts content from a document.

This method can return the text content, table content, and key-value pairs (fields) from the specified document located in the NetSuite File Cabinet. The content returned depends on the features you specify when you call this method (using the options.features parameter). Use the documentCapture.Feature enum to specify the features you want to extract, such as TEXT_EXTRACTION, TABLE_EXTRACTION, and FIELD_EXTRACTION.

This method extracts content synchronously and supports documents up to five pages in length. If you want to extract content from documents longer than five pages, you must submit an asynchronous extraction task using the N/task module. For an example, see Extract Content from a Document Asynchronously.

This method supports PDF, JPG, PNG, and TIFF files. Encrypted files are not supported.

Returns

documentCapture.Document

Supported Script Types

Server scripts

For more information, see SuiteScript 2.1 Script Types.

Governance

100

Module

N/documentCapture Module

Since

2025.2

Parameters

Parameter

Type

Required / Optional

Description

Since

options.file

file.File

required

The document file to extract content from.

The specified file must be located in the NetSuite File Cabinet, be in PDF, JPG, PNG, or TIFF format, and be five pages in length or shorter. You can specify the file using its internal ID or the path to the file in the File Cabinet. For more information, see N/file Module. Encrypted files are not supported.

2025.2

options.documentType

string

optional

The document type.

Note:

This parameter is required if you specify the FIELD_EXTRACTION feature using the options.features parameter.

Use values from the documentCapture.DocumentType enum to set this parameter. By specifying the type of document, the service can apply pretrained models that are optimized for that type, which can provide more accurate extraction results. If you don't specify a document type when you call this method, the OTHERS document type is used by default.

2025.2

options.features

string[]

optional

The features to extract from the specified document.

Use values from the documentCapture.Feature enum to set this property. If you don't specify any features when you call this method, the TEXT_EXTRACTION and TABLE_EXTRACTION features are used by default.

2025.2

options.language

string

optional

The language of the specified document.

Use values from the documentCapture.Language enum to set this property. If you don't specify a language when you call this method, the ENG (English) language is used by default.

2025.2

options.ociConfig

Object

optional

Important:

This object is no longer supported. Any values specified in this object are ignored.

2025.2

options.timeout

number

optional

The timeout period to wait for a response from the service.

By default, the timeout period is 30,000 milliseconds (30 seconds). You can specify a longer timeout period, but you can't specify one that's shorter than 30,000 milliseconds. If you try to specify a shorter timeout period, the default value of 30,000 milliseconds is used instead.

2025.2

Errors

Error Code

Thrown If

DOCUMENT_TOO_LONG

The specified file is longer than five pages. To extract content from documents longer than five pages, submit an asynchronous extraction task using the N/task module. For an example, see Extract Content from a Document Asynchronously.

FEATURES_CANNOT_BE_EMPTY

The list of features to extract is empty (that is, an empty array is specified in the options.features parameter).

FEATURE_1_DOES_NOT_SUPPORT_LANGUAGE_2

A feature is specified (using the options.features parameter) that is not supported in the specified language.

INCOMPATIBLE_DOCUMENT_TYPE_FOR_FEATURE_1

A feature is specified (using the options.features parameter) that is not supported for the specified document type.

INVALID_DOCUMENT_CAPTURE_RESULT

The document capture result provided by the service is invalid.

INVALID_DOCUMENT_TYPE

The specified document type is not included in the documentCapture.DocumentType enum.

INVALID_LANGUAGE

The specified language is not included in the documentCapture.Language enum.

MAXIMUM_PARALLEL_REQUESTS_LIMIT_EXCEEDED

The number of parallel requests to the service is greater than five. A maximum of five parallel requests are supported.

SSS_MISSING_REQD_ARGUMENT

The required options.file parameter is not specified.

UNSUPPORTED_FILE_TYPE

The specified file is not in PDF, JPG, PNG, or TIFF format.

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/documentCapture Module Script Samples.

            // Add additional code
...

const extractedData = documentCapture.documentToStructure({
    file: file.load("SuiteScripts/sample_invoice.pdf"),
    documentType: documentCapture.DocumentType.INVOICE,
    features: [
        documentCapture.Feature.TEXT_EXTRACTION,
        documentCapture.Feature.FIELD_EXTRACTION
    ]
});

...
// Add additional code 

          

Related Topics

General Notices