Record Transformation Method in SuiteScript 2.x
The record transformation method allows you to convert records between types, streamlining order processing and invoice creation.
The record transformation method in SuiteScript 2.x enables developers to transform one type of record into another, leveraging existing record data. This capability is particularly useful for automating processes such as order processing and the creation of item fulfillment transactions and invoices.
How Does the Record Transformation Method Work?
Transforming a record requires specifying certain parameters. The method provides both synchronous and promise-based (asynchronous) variants. The promise version can be particularly beneficial in client scripts where asynchronous processing is preferred.
Method Description
- Functionality: The method transforms a record of one type into another using the data from an existing record.
- Returns: A new record object.
Governance
- Transaction Records: 10 units.
- Custom Records: 2 units.
- All Other Record Types: 5 units.
Supported Script Types
This method can be utilized in both client and server scripts. For a detailed overview of SuiteScript 2.x script types, refer to the SuiteScript 2.x Script Types documentation.
Parameters
The method accepts an options parameter which is a JavaScript object containing the following fields:
| Field Name | Type | Required / Optional | Description |
|---|---|---|---|
fromType | string | Required | The record type of the existing record instance being transformed. This value sets the Record.type property for the record and is read-only. |
fromId | number | Required | The internal ID of the existing record instance being transformed. |
toType | string | Required | The record type of the new record that will be returned after the transformation. |
isDynamic | boolean | Optional | Determines if the new record is created in dynamic mode. Defaults to false. |
defaultValues | Object | Optional | Name-value pairs for default values of fields in the new record. |
Error Handling
You may encounter the following error:
SSS_MISSING_REQD_ARGUMENT: Thrown if a required argument is missing or undefined.
Example Syntax
Here’s how you might implement the transformation method:
1var objRecord = record.transform({2 fromType: record.Type.CUSTOMER,3 fromId: 107,4 toType: record.Type.SALES_ORDER,5 isDynamic: true,6});1record.transform({2 fromType: 'salesorder', 3 fromId: 6, 4 toType: 'invoice', 5 defaultValues: { billdate: '01/01/2019' }6});Supported Transformation Types
The record transformation method supports a variety of transformation types. Here are some noteworthy examples:
- Assembly Build: converts to Assembly Unbuild.
- Cash Sale: can transform into Credit Memo, Invoice, and more.
- Vendor Bill: can convert into Vendor Credit or Vendor Payment.
For a full list of supported transformations and their corresponding record types, check the documentation.
Conclusion
Understanding the nuances of record transformation in SuiteScript 2.x is crucial for effectively utilizing NetSuite's automation capabilities. This knowledge not only aids in improving efficiency but also enhances the accuracy of record management within your applications.
Frequently Asked Questions (4)
Can the record transformation method be used in both client and server scripts in SuiteScript 2.x?
What happens if a required parameter is missing when using the record transformation method?
What are the governance units associated with transforming transaction records using SuiteScript 2.x?
Is it possible to transform a Cash Sale into an Invoice using the record transformation method?
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.
