Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The NetSuite Pro

The NetSuite Pro Logo The NetSuite Pro Logo

The NetSuite Pro Navigation

  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • Advanced PDF Templates in NetSuite
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • Advanced PDF Templates in NetSuite
  • Blog
  • Contact Us
Home/ NetSuite Scripting/Working with Record & Search Modules in SuiteScript 2.1

Working with Record & Search Modules in SuiteScript 2.1

🔹 Introduction

Two of the most commonly used modules in SuiteScript are:

  • N/record → Work with NetSuite records (create, load, update, delete).
  • N/search → Find and retrieve data (saved search results, ad-hoc queries).

Together, these modules let you read and write records programmatically, and they form the foundation of most scripts.


🔹 The Record Module (N/record)

Example 1: Create a Customer

What this does: Creates a new customer record and saves it.

/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/record'], (record) => {
    const execute = () => {
        try {
            const customer = record.create({
                type: record.Type.CUSTOMER,
                isDynamic: true
            });
            customer.setValue({
                fieldId: 'companyname',
                value: 'Test Company Inc.'
            });
            customer.setValue({
                fieldId: 'email',
                value: 'testcompany@example.com'
            });
            
            const customerId = customer.save();
            log.debug('Success', `Customer created with ID: ${customerId}`);
        } catch (e) {
            log.error('Error creating customer', e.message);
        }
    };
    return { execute };
});

Example 2: Load & Update a Record

What this does: Loads an existing Customer by ID and updates its phone number.

/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/record'], (record) => {
    const execute = () => {
        try {
            const customerId = 123; // replace with real internal ID
            const customer = record.load({
                type: record.Type.CUSTOMER,
                id: customerId
            });
            
            customer.setValue({
                fieldId: 'phone',
                value: '555-123-4567'
            });
            
            customer.save();
            log.debug('Success', `Customer ${customerId} phone updated.`);
        } catch (e) {
            log.error('Error updating customer', e.message);
        }
    };
    return { execute };
});

Example 3: Delete a Record

/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/record'], (record) => {
    const execute = () => {
        try {
            const deletedId = record.delete({
                type: record.Type.CUSTOMER,
                id: 123 // replace with real ID
            });
            log.debug('Success', `Customer ${deletedId} deleted.`);
        } catch (e) {
            log.error('Error deleting record', e.message);
        }
    };
    return { execute };
});

🔹 The Search Module (N/search)

Example 4: Load a Saved Search

What this does: Loads a pre-built saved search for Customers and logs results.

/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/search'], (search) => {
    const execute = () => {
        try {
            const customerSearch = search.load({
                id: 'customsearch_my_customer_search' // replace with your saved search ID
            });
            
            customerSearch.run().each(result => {
                log.debug('Customer', `${result.getValue('entityid')} - ${result.getValue('email')}`);
                return true; // continue to next row
            });
        } catch (e) {
            log.error('Error loading saved search', e.message);
        }
    };
    return { execute };
});

Example 5: Create an Ad-Hoc Search

What this does: Searches for active customers directly in script without a saved search.

/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/search'], (search) => {
    const execute = () => {
        try {
            const customerSearch = search.create({
                type: search.Type.CUSTOMER,
                filters: [['isinactive', 'is', 'F']],
                columns: ['entityid', 'email', 'phone']
            });
            
            const results = customerSearch.run().getRange({ start: 0, end: 10 });
            
            results.forEach(result => {
                log.debug('Customer', `${result.getValue('entityid')} | ${result.getValue('email')} | ${result.getValue('phone')}`);
            });
        } catch (e) {
            log.error('Error creating search', e.message);
        }
    };
    return { execute };
});

Example 6: Search + Update in One Script

What this does: Finds the first 10 inactive customers and reactivates them.

/**
 *@NApiVersion 2.1
 *@NScriptType ScheduledScript
 */
define(['N/search', 'N/record'], (search, record) => {
    const execute = () => {
        try {
            const customerSearch = search.create({
                type: search.Type.CUSTOMER,
                filters: [['isinactive', 'is', 'T']],
                columns: ['entityid']
            });
            
            const results = customerSearch.run().getRange({ start: 0, end: 10 });
            
            results.forEach(result => {
                const custId = result.id;
                const customer = record.load({
                    type: record.Type.CUSTOMER,
                    id: custId
                });
                customer.setValue({
                    fieldId: 'isinactive',
                    value: false
                });
                customer.save();
                log.debug('Updated', `Customer ${custId} reactivated.`);
            });
        } catch (e) {
            log.error('Error reactivating customers', e.message);
        }
    };
    return { execute };
});

🔹 Best Practices

  • Use record.submitFields() for lightweight updates (faster than full load/save).
  • Use Saved Searches for complex filters you want non-devs to edit later.
  • Always limit search results or use Map/Reduce for big datasets.
  • Use try–catch + log.error() in every block for debugging.

✅ Key Takeaway

  • N/record is your tool for CRUD operations (Create, Read, Update, Delete).
  • N/search lets you query records efficiently, either using saved searches or ad-hoc filters.
  • Together, these modules form the backbone of most SuiteScripts.
Share
  • Facebook

Sidebar

Ask A Question

Stats

  • Questions 6
  • Answers 6
  • Best Answers 0
  • Users 2
  • Popular
  • Answers
  • Rocky

    Issue in running a client script in NetSuite SuiteScript 2.0 ...

    • 1 Answer
  • admin

    How can I send an email with an attachment in ...

    • 1 Answer
  • admin

    How do I avoid SSS_USAGE_LIMIT_EXCEEDED in a Map/Reduce script?

    • 1 Answer
  • admin
    admin added an answer The issue is usually caused by following Wrong script file… September 14, 2025 at 10:33 pm
  • admin
    admin added an answer Steps to send an Invoice PDF by email: define(['N/email', 'N/render',… August 28, 2025 at 3:05 am
  • admin
    admin added an answer This error means your script hit NetSuite’s governance usage limit… August 28, 2025 at 3:02 am

Top Members

Rocky

Rocky

  • 1 Question
  • 21 Points
Begginer
admin

admin

  • 5 Questions
  • 2 Points

Trending Tags

clientscript netsuite scripting suitescript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

© 2025 The NetSuite Pro. All Rights Reserved