The Complete Guide to NetSuite SuiteScript
Photo by Luca Bravo / Unsplash

NetSuite’s flexibility comes from its powerful customization tools, and SuiteScript is at the heart of this. If you're is looking to break free from the constraints of pre-set workflows, SuiteScript offers a way to transform NetSuite into a system that works with your unique processes and ambitions.

In this guide, I’ll unpack the capabilities of SuiteScript, walk through creating your first script, and share best practices to help you unlock the full potential of NetSuite.


What is SuiteScript?

SuiteScript is NetSuite’s JavaScript-based scripting language, enabling developers (by the end of this article, that'll also be you!) to create tailored solutions that align perfectly with complex business needs.

From automating manual tasks to executing complicated workflows, SuiteScript allows you to set up automations for simple tasks that need to run whenever certain conditions are satisfied.

For example, you could set up a SuiteScript to automatically report inventory levels in your warehouse every day, and create an alert if there is a stock-out for any SKU.

Ultimately with SuiteScripts, you can automate a lot of operations around processes like:


How Does SuiteScript Operate?

At its core, SuiteScript functions by responding to specific triggers (called events) within NetSuite. These triggers can range from user interactions to scheduled events, allowing scripts to respond in real time or execute at set intervals.

Real-World Applications:

📩
Automatically notifying a vendor when inventory levels dip below a threshold.
🔄
Scheduling nightly tasks to reconcile data across departments.
⚠️
Validating input fields on forms to maintain data integrity.


Some Other Practical Use Cases

1. Automating Approval Workflows

Streamline multi-level approvals for purchase orders or invoices by triggering custom scripts based on thresholds or approvers’ roles.

2. Custom Reporting

Develop dashboards that consolidate and visualize data across subsidiaries, providing executives with actionable insights in real-time.

3. Integrations

Synchronize data between NetSuite and third-party applications such as Salesforce, Shopify, Magento or any other CRM or e-commerce platforms or logistics providers.

Read on to learn how you can set something like this up for your NetSuite deployment.


Writing your first SuiteScript

Want to try your hand at SuiteScript? Let’s start simple: creating a script that displays a friendly message when opening a customer record.

Step 1: Enable SuiteScript

Before diving into the code, ensure SuiteScript is enabled:

  1. Navigate to Setup > Company > Enable Features.
  2. Under the SuiteCloud tab, enable Client SuiteScript and agree to the terms.
  3. Click Save.

Step 2: Write the Script

Create a JavaScript file (welcomeMessage.js) containing the following code (you can just copy the text from below):

💡
javascriptCopy codedefine([], function() {
function pageInit(context) {
alert('Welcome to the Customer Record!');
}
return { pageInit: pageInit };
});

Step 3: Upload the Script

  1. Go to Documents > Files > SuiteScripts.
  2. Upload your welcomeMessage.js file into the SuiteScripts folder.

Step 4: Deploy the Script

  1. Navigate to Customization > Scripting > Scripts > New.
  2. Select your uploaded script and create a deployment record.
  3. Set it to apply to Customer Record and save.

Step 5: Test It Out!

Open any customer record in NetSuite. If deployed correctly, a greeting will pop up, confirming your script is active.


Writing Advanced SuiteScripts

Now, let's move to writing something that you can actually use in your day-to-day NetSuite work.

As an example, let's solve this problem:

💡
You want to automatically notify your sales team when inventory levels for any SKU dip below a certain threshold, so that they can create accurate Sales Quotes.



Here's how you can break down the problem:

Step 1: Identify Your Requirements

  1. Threshold: Determine the inventory threshold for each item.
  2. Notification Method: Decide how your sales team will be notified (e.g., email or NetSuite notification).
  3. Trigger: Define when the script should run (e.g., on item inventory update or on a fixed schedule).

Step 2: Set Up the Script in NetSuite

  1. Log in to NetSuite: Go to Customization > Scripting > Scripts > New.
  2. Script Type: Choose the appropriate script type (e.g., Scheduled Script or User Event Script).
  3. Deployment: Set the deployment of the script to the items or schedule it to run periodically.

Step 3: Code the Script

Here’s the SuiteScript code for a Scheduled Script to check inventory levels and notify the sales team via email:

/**
 * @NApiVersion 2.1
 * @NScriptType ScheduledScript
 */
define(['N/record', 'N/search', 'N/email', 'N/runtime'], function (record, search, email, runtime) {

    const THRESHOLD = 10; // Set your threshold level

    function execute(context) {
        try {
            // Search for inventory items below threshold
            const inventorySearch = search.create({
                type: search.Type.INVENTORY_ITEM,
                filters: [
                    ['quantityavailable', 'lessthan', THRESHOLD]
                ],
                columns: ['itemid', 'quantityavailable']
            });

            let lowStockItems = [];
            
            inventorySearch.run().each(result => {
                const itemId = result.getValue('itemid');
                const quantityAvailable = result.getValue('quantityavailable');
                lowStockItems.push(`${itemId} (Available: ${quantityAvailable})`);
                return true;
            });

            if (lowStockItems.length > 0) {
                // Notify the sales team
                sendNotification(lowStockItems);
            } else {
                log.audit('No Low Stock Items', 'All items are above the threshold.');
            }
        } catch (error) {
            log.error('Error in Low Stock Notification', error);
        }
    }

    function sendNotification(lowStockItems) {
        const salesTeamEmail = 'sales@example.com'; // Replace with your sales team email
        const subject = 'Low Stock Alert';
        const body = `The following items have inventory levels below the threshold:\n\n${lowStockItems.join('\n')}`;

        email.send({
            author: runtime.getCurrentUser().id,
            recipients: salesTeamEmail,
            subject: subject,
            body: body
        });

        log.audit('Notification Sent', `Email sent to ${salesTeamEmail}`);
    }

    return { execute };
});

SuiteScript to notify your Sales Team on low inventory levels.


This SuiteScript does the 3 things below:

  1. Create a search function for the inventory items
  2. Run the threshold check on each item in that search
  3. Notify the Sales Team for every item that is below the threshold


Taking SuiteScript to Production

SuiteScript offers a rich toolkit for building more complex and robust solutions, that can actually add value in your production NetSuite environment.

1. Event-Driven Logic

SuiteScript supports user event scripts, client scripts, and scheduled scripts to execute actions precisely when needed. You can trigger actions on any event - whether that is a data change in NetSuite, or a regular interval like 8 AM every day.

2. Comprehensive APIs

Developers can leverage APIs to connect NetSuite with external platforms like payment gateways or CRM systems. This allows you to extend NetSuite's capabilities, outside of the core ERP.

3. SuiteScript Development Framework (SDF)

For large projects, SDF provides advanced tools for developers. It introduces things like version control (you might be familiar with this if you use BitBucket or GitHub) and deployment automation - along with project management.


Best Practices for SuiteScript Development

1. Keep it Modular

Break your scripts into reusable functions or modules for easier debugging and maintenance. If you've ever worked with functions in programming, this is pretty similar - one script should do exactly one thing, and nothing more.

2. Monitor Governance Limits

NetSuite enforces governance rules to prevent overuse of system resources and usage units. Use methods like runtime.getCurrentScript().getRemainingUsage() to stay within limits.

3. Thorough Testing

Always test scripts in a sandbox environment before deploying to production. Unit and integration tests are essential. If you're not sure you should be deploying a script to your production environment, get your internal teams to test it out on the sandbox first.

4. Document Everything

Good documentation reduces onboarding time for new developers and prevents misinterpretation of your code’s purpose.


SuiteScript 2.x vs 1.0: Which Should You Use?

SuiteScript 2.x is the modern standard, offering modular architecture and enhanced API capabilities, while SuiteScript 1.0 serves legacy use cases.

FeatureSuiteScript 1.0SuiteScript 2.x
ArchitectureMonolithicModular
Dependency ManagementManualAutomatic
Coding StyleFunctionalObject-Oriented
API CoverageBasicComprehensive



Unlocking the Full Potential of NetSuite and SuiteScript

While SuiteScript is powerful, integrating AI workflow automation platforms like Nanonets elevates its functionality. Nanonets automates repetitive processes, validates data with unmatched accuracy, and provides intelligent insights—all seamlessly integrated into NetSuite. From AP workflows to financial analytics, Nanonets enhances every layer of automation.

Getting started with Nanonets can be as easy as a 15-minute connect with an automation expert. Set up a time of your choosing using the link below.