Week 3 • Module 5

N/record Module

Server-side record creation, loading, updating, and sublist manipulation

📚 What is a Record?

In NetSuite, a record is any entity stored in the database that can be retrieved as key-value pairs. Sales Orders, Customers, Items, and Custom Records are all examples of records.

Viewing Raw Record Data

Add &xml=T to any record URL to see the raw XML data. This reveals all field IDs and their current values—invaluable for development.

💡 Show Internal IDs

Enable "Show Internal IDs" in your preferences (Home → Set Preferences → Defaults) to see field IDs when hovering over fields in the UI.

🔧 Core Record Operations

record.create()

Creates a new record in memory. The record must be saved with .save() to persist to the database.

const newCustomer = record.create({
    type: record.Type.CUSTOMER,
    isDynamic: true
});
newCustomer.setValue({ fieldId: 'companyname', value: 'Acme Corp' });
const customerId = newCustomer.save();

record.load()

Loads an existing record from the database for reading or modification.

const salesOrder = record.load({
    type: record.Type.SALES_ORDER,
    id: 12345,
    isDynamic: false
});
const customer = salesOrder.getValue({ fieldId: 'entity' });

record.copy()

Creates a copy of an existing record—same as the "Make Copy" action in the UI.

const copiedOrder = record.copy({
    type: record.Type.SALES_ORDER,
    id: 12345
});

record.transform()

Converts one record type to another (e.g., Sales Order → Item Fulfillment).

const fulfillment = record.transform({
    fromType: record.Type.SALES_ORDER,
    fromId: 12345,
    toType: record.Type.ITEM_FULFILLMENT
});

record.delete()

Permanently removes a record from the database.

record.delete({
    type: record.Type.CUSTOMER,
    id: 99999
});

📝 getValue() vs getText()

NetSuite fields often have two representations:

Method Returns Example
getValue() Internal ID (number/string) 227
getText() Display value (human-readable) "Zenith and Acme Installation"
// Get the internal ID of the customer
const customerId = salesOrder.getValue({ fieldId: 'entity' }); // 227

// Get the display name of the customer
const customerName = salesOrder.getText({ fieldId: 'entity' }); // "Zenith and Acme"

⚠️ When to Use Each

Use getValue() for logic and comparisons. Use getText() for display purposes (emails, reports, logs).

📊 Working with Sublists

Sublists are the line-item sections on records (Items on Sales Orders, Addresses on Customers). They require special methods:

Getting Line Count

const lineCount = salesOrder.getLineCount({ sublistId: 'item' });

Reading Sublist Values

for (let line = 0; line < lineCount; line++) {
    const item = salesOrder.getSublistValue({
        sublistId: 'item',
        fieldId: 'item',
        line: line
    });
    const quantity = salesOrder.getSublistValue({
        sublistId: 'item',
        fieldId: 'quantity',
        line: line
    });
}

Setting Sublist Values

salesOrder.setSublistValue({
    sublistId: 'item',
    fieldId: 'quantity',
    line: 0,
    value: 10
});

📚 Finding Sublist IDs

Use the &xml=T trick to find sublist IDs. Look for <machine name="item"> elements in the XML output.

⚡ submitFields() for Efficiency

When you only need to update a few fields, submitFields() is more efficient than load/save:

// Less efficient: 4 governance for load + 20 for save = 24 units
const rec = record.load({ type: 'salesorder', id: 123 });
rec.setValue({ fieldId: 'memo', value: 'Updated' });
rec.save();

// More efficient: Only 4 governance units
record.submitFields({
    type: 'salesorder',
    id: 123,
    values: {
        memo: 'Updated'
    }
});

✅ Best Practice

Use submitFields() when updating 1-3 fields. Use load()/save() when you need to read values, work with sublists, or make many changes.

🔗 UI Equivalents

SuiteScript record operations mirror actions users take in the UI:

SuiteScript UI Equivalent
record.create() Click "New" button
record.load() Open existing record
record.copy() Actions → Make Copy
record.transform() Click "Fulfill" on Sales Order
record.save() Click "Save" button

📖 Finding This in the Docs

To look up N/record methods:

  1. Go to docs.oracle.com → SuiteScript 2.x Modules
  2. Click on N/record Module
  3. Browse Methods (load, create, copy, delete, submitFields) and Record Object properties

Key pages to bookmark:

🎯 Key Takeaways