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
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.jsonThe SPA object
<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>urlmust be unique in the account (C2C).- List standard roles in
audienceroles.audienceallroles=Tfailed 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:
/**
* @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));
};/**
* @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:
gulp-typescriptcompilessrc/SuiteApps/**/*.tsxto ES modules inbuild/.rollupbundles each entry (SpaClient.js,SpaServer.js) as AMD intosrc/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 theNpatterns rollup tries to installN/recordfrom npm.- A
bannerwith the@NApiVersion/@NScriptTypecomment copied from the source file. Rollup removes comments, and NetSuite needs them. - An alias so
import ... from 'nsui'resolves to your copy ofdist/nsui.esm.js. NSUI is bundled intoSpaClient.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
.cssfiles 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
applicationlayout, 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-dialogandconfirm()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):
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 withINVALID_RETURN_DATA_FORMAT(Batchline). - A login page instead of JSON means the session expired or the role lacks permission.
- When
fetchfails 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'spage-size; it renders every row on the current page.
Links and navigation
- 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.replaceStatefor redirects and sub-state, andpushStatefor 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).
applicationlayout fills the viewport;naturaluses 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-fonton a parent element to choose another font; see Fonts.
Testing
- Before deploy: load the built
SpaClient.jsin a local page with a smalldefinestub and a fakeHtmlWrapper(ofElement: (el) => el), then callrun(). 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).
TypeScript and JSX
Type-safe nsui-* tags in TSX with NSUI's h() runtime, React 19 or plain DOM.
Fonts
Use NetSuite's font by default, or load your own and set three tokens.
NSUI is a community project. It is not an official Oracle NetSuite product. NetSuite is a trademark of Oracle.