The N/record module is the most fundamental module in SuiteScript 2.x. It provides full CRUD (Create, Read, Update, Delete) operations on any NetSuite record type β from Sales Orders and Customers to custom records. Every serious SuiteScript developer uses this module daily.
Loading the N/record Module
define(['N/record'], (record) => {
// your code here
return {};
});
Creating a Record
Use record.create() to instantiate a new record object in memory. Set its fields, then call save() to persist it to NetSuite.
const newRecord = record.create({
type: record.Type.CUSTOMER,
isDynamic: true
});
newRecord.setValue({ fieldId: 'companyname', value: 'Acme Corp' });
newRecord.setValue({ fieldId: 'subsidiary', value: 1 });
const customerId = newRecord.save();
log.debug('Created customer', customerId);
Loading an Existing Record
const soRecord = record.load({
type: record.Type.SALES_ORDER,
id: 12345,
isDynamic: false
});
const status = soRecord.getValue({ fieldId: 'status' });
log.debug('SO Status', status);
Updating a Record with submitFields()
For updating just one or two fields, use record.submitFields() instead of loading the full record. This is far more governance-efficient.
record.submitFields({
type: record.Type.CUSTOMER,
id: 12345,
values: { email: 'new@email.com', phone: '555-1234' }
});
Deleting a Record
record.delete({
type: record.Type.CUSTOMER,
id: 12345
});
Working with Sublists
Sublists (such as line items on a Sales Order) require their own set of methods. Use getLineCount(), getSublistValue(), setSublistValue(), and insertLine().
const lineCount = soRecord.getLineCount({ sublistId: 'item' });
for (let i = 0; i < lineCount; i++) {
const item = soRecord.getSublistValue({ sublistId: 'item', fieldId: 'item', line: i });
const qty = soRecord.getSublistValue({ sublistId: 'item', fieldId: 'quantity', line: i });
log.debug('Line ' + i, item + ' x ' + qty);
}
Key Methods Reference
| Method | Description |
|---|---|
record.create(options) | Create a new record in memory |
record.load(options) | Load an existing record by type and ID |
record.copy(options) | Copy an existing record |
record.delete(options) | Delete a record permanently |
record.submitFields(options) | Update specific fields without loading the full record |
record.transform(options) | Transform one record type to another (e.g., SO to Invoice) |
recObj.getValue(options) | Get a body field value |
recObj.setValue(options) | Set a body field value |
recObj.getSublistValue(options) | Get a sublist field value |
recObj.setSublistValue(options) | Set a sublist field value |
recObj.getLineCount(options) | Get the number of lines in a sublist |
recObj.save(options) | Save the record to NetSuite |
Governance Cost
Loading a record costs 10 governance units. Saving a record costs 20 governance units. submitFields() costs just 10 units. Always prefer submitFields() when updating only a few fields, and use N/search to read field values in bulk rather than loading individual records.