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.
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 Name | Return Type | Description | Supported Script Types |
|---|---|---|---|
Document.mimeType | string | Contains the MIME type of the document. | Server scripts |
Document.pages | documentCapture.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:
1// Sample code to extract document text2const extractedData = documentCapture.documentToStructure({3 file: file.load("SuiteScripts/sample_invoice.pdf"),4 documentType: documentCapture.DocumentType.INVOICE5});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
mimeTypeorpagesproperty directly will cause this error since these properties are read-only.
- Thrown If: Attempting to set the value of the
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.
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, andTIFF.
Frequently Asked Questions (4)
What permissions are required to access Document Object Members in SuiteScript 2.1?
How does the Document.mimeType property handle incorrect file extensions?
Is it possible to modify the mimeType or pages properties of a Document object directly?
Can SuiteScript 2.1 Document Objects handle documents with more than five pages?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
