Document Object Members for SuiteScript 2.1 Reference

Document Object Members provide essential properties and methods for SuiteScript 2.1, enabling MIME type retrieval and document page handling.

·2 min read·View Oracle Docs

Starting in SuiteScript 2.1, Document Object Members are crucial for managing document data in NetSuite scripts. These members allow developers to interact with document properties and methods to extract and manipulate data effectively.

What Are Document Object Members?

The Document Object in SuiteScript provides essential properties and methods that enable developers to handle document-related operations. It includes information about the document type, its pages, and allows access to the document's textual content.

Document Properties

The Document object has the following primary properties:

Property NameReturn TypeDescriptionSupported Script Types
Document.mimeTypestringContains the MIME type of the document.Server scripts
Document.pagesdocumentCapture.Page[]Lists the pages contained in the document.Server scripts

Document Methods

The Document object provides essential methods to access and manipulate document data:

Document.getText()

Returns the entire text content of the document.

Example:

suitescript
1// Sample code to extract document text
2const extractedData = documentCapture.documentToStructure({
3 file: file.load("SuiteScripts/sample_invoice.pdf"),
4 documentType: documentCapture.DocumentType.INVOICE
5});
6
7const documentText = extractedData.getText();

Supported MIME Types

The Document.mimeType property can return various MIME types, including:

  • JPG - image/jpeg
  • PDF - application/pdf
  • PNG - image/png
  • TIFF - image/tiff

Ensure the file's extension corresponds correctly to the MIME type in your scripts.

Error Handling

When interacting with these properties, a common error might arise:

  • Error Code: READ_ONLY
    • Thrown If: Attempting to set the value of the mimeType or pages property directly will cause this error since these properties are read-only.

Practical Application

When using the Document object in SuiteScript, remember that the maximum number of pages returned in a typical call is five. If you require longer documents, asynchronous processing is possible, enabling handling of documents with more pages.

In conclusion, utilizing Document Object Members effectively can streamline document processing in your SuiteScripts, making data extraction and manipulation more efficient.

Source: This article is based on Oracle's official NetSuite documentation.

Key Takeaways

  • Document Object Members in SuiteScript 2.1 include properties for MIME type and pages.
  • Developers can use methods like getText() to retrieve document content.
  • Proper error handling is crucial to manage read-only property restrictions.
  • Document MIME types include JPG, PDF, PNG, and TIFF.

Frequently Asked Questions (4)

What permissions are required to access Document Object Members in SuiteScript 2.1?
The article does not specify the exact permissions required for accessing Document Object Members. Refer to NetSuite's role permissions documentation for more details.
How does the Document.mimeType property handle incorrect file extensions?
The article advises ensuring the file's extension corresponds correctly to the MIME type in your scripts, as mismatches may cause errors.
Is it possible to modify the mimeType or pages properties of a Document object directly?
No, the mimeType and pages properties are read-only, and attempting to set their values directly will cause a READ_ONLY error.
Can SuiteScript 2.1 Document Objects handle documents with more than five pages?
Yes, for documents larger than five pages, asynchronous processing is suggested to enable handling of longer documents effectively.
Source: Document Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →