No history yet

Introduction to SuiteScript

What is SuiteScript?

NetSuite is a powerful tool for running a business, but every business is unique. That's where SuiteScript comes in. It's NetSuite's special toolkit that lets you customize and extend the platform to fit your exact needs. Think of it as a way to teach NetSuite new tricks.

At its core, SuiteScript is built on JavaScript, one of the most popular programming languages in the world. This means if you have some experience with web development, you'll feel right at home.

With SuiteScript, you can automate repetitive tasks, create custom workflows, build entirely new applications within NetSuite, and connect NetSuite to other software. It's the key to unlocking the full potential of the platform and making it work for you, not the other way around.

The Evolution from 1.0 to 2.x

SuiteScript has been around for a while, and it has evolved significantly. The original version, SuiteScript 1.0, was a procedural, function-based language. It got the job done, but as NetSuite and the web grew more complex, a more modern approach was needed.

Enter SuiteScript 2.x. This isn't just a minor update; it's a complete redesign that aligns with modern JavaScript development practices. It introduces a modular architecture, which makes code cleaner, more reusable, and easier to manage.

FeatureSuiteScript 1.0SuiteScript 2.x
ArchitectureProceduralModular (AMD)
API StyleGlobal functions (e.g., nlapiCreateRecord)Modules with methods (e.g., record.create)
SyntaxOlder JavaScript (ES3)Modern JavaScript (ES2015+)
Code OrganizationSingle file, less structureOrganized into self-contained modules
ReadabilityCan become hard to followClearer and more maintainable

While you might still encounter some older 1.0 scripts, all new development should use SuiteScript 2.x. It's more powerful, more efficient, and the standard for NetSuite customization today.

A Look at a 2.x Script

The best way to understand SuiteScript 2.x is to see it in action. Let's look at the basic structure of a simple script. Don't worry about understanding every single detail yet. The goal is to see how the pieces fit together.

/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(['N/record', 'N/log'],
  function(record, log) {
    function beforeLoad(context) {
      log.debug({
        title: 'Script Triggered',
        details: 'The beforeLoad event occurred on record: ' + context.newRecord.id
      });
    }

    return {
      beforeLoad: beforeLoad
    };
  });

This script might look a bit complex, but it follows a clear pattern. Let's break it down:

  1. JSDoc Header: The comments at the very top (/** ... */) are required. @NApiVersion tells NetSuite which version of the API to use (always use 2.1 for new scripts). @NScriptType defines what kind of script this is. In this case, it's a UserEventScript, which runs automatically when a user interacts with a record (like opening, creating, or saving it).

  2. define Function: This is the heart of the modular system. It lists the built-in NetSuite modules the script needs to do its job. Here, we're asking for the N/record module to work with records and the N/log module for logging information.

  3. Callback Function: The define statement includes a function that receives the requested modules as arguments (record, log). All your script's logic goes inside this function.

  4. Entry Points: A script has specific functions that NetSuite calls at certain times. These are called entry points. In our example, beforeLoad is an entry point that runs right before a record is loaded for a user to see.

  5. return Statement: Finally, the script returns an object that maps the entry point names to the functions that handle them. This tells NetSuite exactly which function to run for the beforeLoad event.

This modular structure keeps code organized. Instead of having a single massive file, you create small, focused modules that are easier to test, reuse, and understand.

Now that you've seen the basic structure, you're ready to start exploring what you can build with SuiteScript.