Getting Started with N/record

In SuiteScript 2.0, one of the foundational modules that developers rely on for manipulating records in NetSuite is the N/record module. It’s a versatile module allowing you to create, read, update, and delete various records. This guide will walk you through the basics, complete with examples.


1. Loading a Record

To work with existing records, you first need to load them into your script.

Example: Loading a customer record

2. Creating a Record

You can also create new records from scratch.

Example: Creating a new customer record

3. Setting Field Values

Once you have a record object (either from loading or creating), you can set various field values.

Example: Setting multiple field values

4. Saving a Record

After making changes or creating a new record, you need to save it to commit your changes.

Example: Saving the customer record

5. Deleting a Record

If you need to remove a record, you can do so with the delete function.

Example: Deleting a customer record

6. Working with Sublists

Many records in NetSuite have sublists, like the item sublist on sales orders. You can add lines to a sublist, set sublist field values, and more.

Example: Adding a line item to a sales order


Tips:

  • Always wrap your script operations in a try-catch block to handle any potential errors.
  • Avoid hard coding internal IDs. Use script parameters or configuration records where possible.
  • Be aware of governance limits when working with records. Each create, load, and save operation consumes usage units.

The N/record module offers a comprehensive API to manipulate NetSuite records. By mastering its functions, you’ll have the power to build robust solutions that interact seamlessly with your data. Happy scripting! Contact Katoomi today to learn more.

Other “Getting Started” Posts: