Skip to Content
NSUI

NetSuite SPA

Build a NetSuite Single Page Application with NSUI, JSX and the SuiteCloud gulp build.

A NetSuite Single Page Application (SPA) is a SuiteApp object that NetSuite serves at /spa-app/<publisher>.<project>/<url>. NSUI fits the "plain DOM" pattern: build the page with NSUI components, then hand one root element to NetSuite.

This recipe was verified live on a NetSuite Next account (2026-12-02): rendering, JSX props, the data grid with inline editing and Tab navigation, form controls, dialogs and toasts. Lessons marked (C2C) or (Batchline) come from two production NetSuite SPAs and were not re-tested here.

Project layout

Text
src/
  manifest.xml                      SuiteApp: publisherid + projectid
  Objects/custspa_orders.xml        the SPA object
  SuiteApps/com.acme.orders/orders/ TypeScript source (one folder per SPA)
    SpaClient.tsx                   run(context): builds the page
    SpaServer.ts                    initializeSpa(): server init
    App.tsx
  FileCabinet/SuiteApps/com.acme.orders/orders/
    SpaClient.js  SpaServer.js      AMD bundles written by the build
gulpfile.mjs
tsconfig.json

The SPA object

src/Objects/custspa_orders.xml
<singlepageapp scriptid="custspa_orders">
  <name>Order Desk</name>
  <url>orders</url>
  <folder>[/SuiteApps/com.acme.orders/orders/]</folder>
  <clientscriptfile>[/SuiteApps/com.acme.orders/orders/SpaClient.js]</clientscriptfile>
  <serverscriptfile>[/SuiteApps/com.acme.orders/orders/SpaServer.js]</serverscriptfile>
  <audienceallroles>F</audienceallroles>
  <audienceroles>ADMINISTRATOR|SALES_PERSON</audienceroles>
  <executeas></executeas>
</singlepageapp>
  • url must be unique in the account (C2C).
  • List standard roles in audienceroles. audienceallroles=T failed on accounts that reference deleted roles (C2C). Add custom roles in the UI after install.
  • Paths in a SuiteApp start with /SuiteApps/<appid>/, not /SuiteScripts.

Client entry

NetSuite calls run(context). Build your page into a div and pass it in one HtmlWrapper:

SpaClient.tsx
/**
 * @NApiVersion 2.1
 */
import { HtmlWrapper } from '@uif-js/component';
import { App } from './App';

export const run = (context) => {
  context.setLayout?.('application'); // fill the viewport; 'natural' = content height
  const root = document.createElement('div');
  root.appendChild(App());
  context.setContent(HtmlWrapper.ofElement(root));
};
SpaServer.ts
/**
 * @NApiVersion 2.1
 * @NScriptType SpaServerScript
 */
export const initializeSpa = (_context) => {};

The server script cannot pass data to the client page (C2C, Batchline). Load data from the client (see Data).

App.tsx uses NSUI's JSX. See TypeScript and JSX for the tsconfig.

Build: gulp, tsc, rollup

The build follows Oracle's SuiteCloud SPA samples:

  1. gulp-typescript compiles src/SuiteApps/**/*.tsx to ES modules in build/.
  2. rollup bundles each entry (SpaClient.js, SpaServer.js) as AMD into src/FileCabinet/SuiteApps/....

Rollup settings that matter:

  • format: 'amd', amd: { autoId: false }
  • external: ['@uif-js/core', '@uif-js/core/jsx-runtime', '@uif-js/component', /^N$/, /^N\//]: NetSuite provides these at run time. Without the N patterns rollup tries to install N/record from npm.
  • A banner with the @NApiVersion / @NScriptType comment copied from the source file. Rollup removes comments, and NetSuite needs them.
  • An alias so import ... from 'nsui' resolves to your copy of dist/nsui.esm.js. NSUI is bundled into SpaClient.js (about 67 KB with a small app).

A complete working example is in the NSUI repository under qa/spa/ (gulpfile.mjs, tsconfig.json, src/). Build with npx gulp bundle, then deploy with suitecloud project:deploy.

What NSUI handles for you

  • Styles. NSUI styles live in Shadow DOM, so no CSS file is needed. This avoids the SPA stylesheet problem: NetSuite did not serve SPA .css files on one account (C2C). UIF does not style plain inputs and buttons (C2C); NSUI controls bring their own styles.
  • AMD. NSUI runs inside the SPA's AMD bundle next to NetSuite's global define.
  • The Tab key. In application layout, UIF stops Tab in a document capture listener. The data grid's cell editor handles Tab, Enter and Escape itself, so Tab moves to the next editable cell. Plain form controls keep the browser's normal Tab order.
  • Dialogs. nsui-dialog and confirm() use the native <dialog> top layer, above NetSuite's header and bottom bar.

Data

Read and write data with fetch to a RESTlet or Suitelet in the same account (C2C, Batchline):

TypeScript
const res = await fetch(restletUrl, {
  method: 'POST',
  credentials: 'same-origin',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ action: 'lines', id }),
});
const text = await res.text();
let body;
try { body = JSON.parse(text); } catch { throw new Error('Signed out, or no permission'); }
if (!body.ok) throw new Error(body.error.message);
grid.rows = body.data;
  • The session cookie authenticates the call; no token is needed.
  • A RESTlet must return JSON text (JSON.stringify(...)). Returning an object fails with INVALID_RETURN_DATA_FORMAT (Batchline).
  • A login page instead of JSON means the session expired or the role lacks permission.
  • When fetch fails with a generic error, the real error is in the script's Execution Log (C2C).
  • Use one reply shape for every call, for example { ok: true, data } or { ok: false, error: { code, message } } (Batchline).
  • Large lists: read with runPaged({ pageSize: 1000 }), and call the RESTlet one request at a time (Batchline). Set the grid's page-size; it renders every row on the current page.
  • NetSuite Next drops the #hash. It redirects /spa-app/... to /next/spa-app/... and keeps the query string, not the hash (Batchline). Put deep-link targets in the query (?order=123) and turn them into your route on start.
  • Use history.replaceState for redirects and sub-state, and pushState for user navigation (C2C, Batchline).

Layout

  • NetSuite Next has a fixed bar at the bottom of the screen. Leave room for it in full-height layouts (Batchline).
  • application layout fills the viewport; natural uses the content height.
  • NetSuite pages load Oracle Sans. NSUI's default font stack starts with "Oracle Sans", so its controls match the page; where Oracle Sans is not loaded (for example a full-page Suitelet with your own HTML), the system font applies. Set --nsui-font on a parent element to choose another font; see Fonts.

Testing

  • Before deploy: load the built SpaClient.js in a local page with a small define stub and a fake HtmlWrapper (ofElement: (el) => el), then call run(). This catches runtime errors in seconds.
  • Live: deploy to a test account and check the page in the browser. Save screenshots of what you tested.
  • CI: if you commit the built bundles, check in CI that they match the source (C2C).
  • The SPA client is served with no-store, so you do not need version parameters to bust caches (C2C).

NSUI is a community project. It is not an official Oracle NetSuite product. NetSuite is a trademark of Oracle.

On this page