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
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category