What we do
Tools
Industries
Department
How we workLet's talk →
Home/NetSuite/NetSuite SuiteScript
NetSuite SuiteScript

SuiteScript in NetSuite: Matching the Script Type to What Sets It Off

Reps keep saving sales orders with discounts their role shouldn't allow, and the workflow builder can't check the price against the customer's contract. That's the point where a NetSuite admin hears "that needs a script." SuiteScript is JavaScript that runs inside NetSuite, started by a record saving, a form loading, a timer, or a call from outside. The type you pick decides what can start it and how much work it may do before NetSuite cuts it off.

What starts the code, and which SuiteScript type answers it

Usage units are NetSuite's governance budget: each API call costs some, and a script that runs out stops with an error. Mass update and workflow action scripts exist too, for narrower jobs.

What has to happen Script type Worth knowing
A check or change the moment a record is created, edited or deleted User event, with beforeLoad, beforeSubmit and afterSubmit entry points 1,000 units per run. A record saved by another user event script doesn't fire user events again, so chained logic needs planning.
Field behavior while someone fills in a form Client script: pageInit, fieldChanged, validateField, saveRecord Runs in the browser only. CSV imports, integrations and server scripts never see it.
A batch job on a timer, nightly or hourly Scheduled script 10,000 units per run. Anything that grows with your data belongs in map/reduce instead.
Thousands of records worked through in one job Map/reduce: getInputData, map, reduce, summarize NetSuite splits the work and yields on its own, so the whole run has no overall unit cap. Errors per record are collected for the summarize stage.
A custom page or form inside NetSuite Suitelet 1,000 units per request. Good for approval screens and internal tools.
An outside system calling in with data shaped its own way RESTlet 5,000 units per call. Sits beside SuiteTalk, which our NetSuite API page covers.

Scripts that pass on test orders and fail on real ones

Loading and saving a full record inside a loop

How you'll know: Fine on 20 sandbox orders, then SSS_USAGE_LIMIT_EXCEEDED on the month-end batch.

Fix: Read the fields you need with a search, SuiteQL through N/query, or search.lookupFields, and update with record.submitFields rather than a full load and save. If the volume keeps growing, move the job to map/reduce.

A business rule that only lives in a client script

How you'll know: The rule holds when people type orders in, but orders from an import or the web store break it.

Fix: Enforce it again in a beforeSubmit user event, which runs on the server whatever created the record. Keep the client script for the friendly warning.

CSV imports skipping your server logic

How you'll know: Records loaded by import are missing the values your user event sets.

Fix: The import's advanced options include Run Server SuiteScript and Trigger Workflows. With it off, user event scripts don't run for that import. Decide per import, because some bulk loads are meant to skip them.

A deployment left on Testing

How you'll know: It works for the person who wrote it and nobody else.

Fix: A deployment with status Testing runs only for the script owner. Set it to Released, and set the audience and execution contexts it should run in.

From a .js file to a released script, through SDF

You can upload a file to the File Cabinet and create the script record by hand. SDF keeps the code, the script record and the deployment in one project you can version and redeploy.

  1. 1

    Set up an account customization project

    Install the SuiteCloud CLI for Node.js or the SuiteCloud extension for VS Code, create a project, and authorize it against your sandbox account.

  2. 2

    Write the script with its JSDoc tags

    The top of the file declares @NApiVersion 2.1 and the type, such as @NScriptType UserEventScript. The code loads modules like N/record and N/search through define. 2.1 lets you use modern JavaScript syntax; 2.0 still runs for older files.

  3. 3

    Describe the script record and deployment as objects

    Each script gets an XML object with a customscript_ ID, and each deployment a customdeploy_ ID: which record type it applies to, its status and its log level. These live in the project next to the code.

  4. 4

    Validate and deploy to the sandbox

    Run the project's validation, then deploy. Test with real volumes: a copy of last month's orders tells you far more about governance than five hand-made ones.

    Watch for: the execution log on the deployment. Set the log level to Debug while testing and back to Error or Audit before release.

  5. 5

    Release to production from the same project

    Point the project at production and deploy the same objects. Nobody re-creates the deployment by hand, so sandbox and production can't drift apart.

SuiteScript questions from admins and developers

What is SuiteScript, in NetSuite terms?

It's NetSuite's JavaScript platform for code that runs inside your account. A script is attached to an event (a record saving, a form loading, a schedule, or an incoming HTTP call) through a script record and a deployment, and it calls NetSuite through modules such as N/record, N/search and N/query.

What's the difference between SuiteScript 1.0 and 2.0 (and 2.1)?

1.0 is the original global-function API. 2.0 replaced it with modules you load as you need them, and 2.1 keeps the 2.0 modules while allowing newer JavaScript syntax. New work goes in 2.1. Many older accounts still run 1.0 files, and they keep working, but adding to them in 1.0 only grows the part nobody wants to touch.

What is a RESTlet in NetSuite?

A SuiteScript type that acts as your own HTTP endpoint. An outside system calls it with GET, POST, PUT or DELETE, and your code decides what to read or write and what shape to answer in. Each call gets 5,000 usage units, and callers authenticate with token-based authentication or OAuth 2.0.

Can I learn SuiteScript myself, or do I need a developer?

An admin who knows some JavaScript can learn to write a small user event or client script from Oracle's help center and the SuiteScript samples. The harder skills are designing for governance, handling records the script didn't expect, and deploying safely. That's the work n-frames is brought in for: scripts that keep running when the order volume doubles.

Is SuiteScript the same thing as NetSuite's API?

No. SuiteTalk (REST and SOAP web services) is how outside systems read and write NetSuite records over standard endpoints. SuiteScript is code that runs inside NetSuite. RESTlets bridge the two: written in SuiteScript, called from outside. Our NetSuite API page covers SuiteTalk and SuiteQL.

How many usage units does a SuiteScript get?

It depends on the type: 1,000 per run for user event and Suitelet scripts, 5,000 per RESTlet call, 10,000 per scheduled script run, and 1,000 per record for mass updates. Map/reduce has no cap on the whole run because NetSuite splits the work and yields between pieces.

Let's talk

Tell us the one thing your team does manually that eats up time. We read every message and reply within a day.