Records

SuiteScript Record Types

Working with Record Types

SuiteScript record types include salesorder and customer for CRUD.

Understanding SuiteScript Record Types

In SuiteScript, record types are essential for interacting with the NetSuite database. Records represent the different types of data that can be stored and manipulated, such as transactions, entities, and custom records. Two common record types are salesorder and customer, which are used for managing sales transactions and customer information, respectively.

Working with SalesOrder Records

The salesorder record type is used to manage sales transactions within NetSuite. You can perform Create, Read, Update, and Delete (CRUD) operations on these records using SuiteScript. Below is an example of how to create a new sales order record.

In the example above, a new sales order record is created dynamically. The entity field is set to the customer's ID, and the item field is set to the item's ID. Finally, the record is saved, and the sales order ID is returned.

Handling Customer Records

Customer records are crucial for storing and managing details about your clients. You can perform CRUD operations on customer records in a similar fashion to sales orders. Below is an example of updating a customer's email address using SuiteScript.

Here, we load an existing customer record in dynamic mode, update the email field with a new email address, and then save the changes.

Best Practices for Using Record Types

  • Use Dynamic Mode: When creating or updating records, using dynamic mode allows for easier handling of sublists and fields.
  • Validate Data: Always validate the data being set on records to prevent errors and inconsistencies.
  • Handle Errors: Implement error handling to manage any issues that may arise during CRUD operations.