Single Page Application Server Script
The SPA server script file is the script file associated with the script record. It acts as a plug-in with an API that can modify the response (for example, add scripts or perform validations).
You can load most server-side SuiteScript modules from the SPA server script. For examples, see SPA Server Script Basic Examples using SuiteScript modules.
The SPA server script has the following structure:
-
It includes the two JSDoc tags,
@NApiVersionand@NScriptType, declaring the appropriate version (2.1) and script type (SpaServerScript)./** * @NApiVersion 2.1 * @NScriptType SpaServerScript */ -
It implements and exports an
initializeSpa(context)entry point function. This function receives a context parameter, an object that contains thecontext.addStyleSheet(options)method./** * @NApiVersion 2.1 * @NScriptType SpaServerScript */ export const initializeSpa = (context) => {}; -
The
context.addStyleSheet(options)method adds a style sheet to the SPA. It returnsvoid.This method has the following parameters:
Parameter
Type
Required/Optional
Description
relativePathstring
At least one is required (and not null).
The path to the CSS file relative to the assets folder (for example, "/main.css").
urlstring
At least one is required (and not null).
The URL where the CSS file is located (for example, "http://sampleweb.com/css/main.css").
The URL member overrides any value provided in the
relativePathmember.The following example shows how to use the
context.addStyleSheet(options)method with both parameters specified. Theurlgets precedence over therelativePath./** * @NApiVersion 2.1 * @NScriptType SpaServerScript */ import log from 'N/log'; export const initializeSpa = (context) => { context.addStyleSheet({ relativePath: "/main.css", url: "http://sampleweb.com/css/main.css"}); log.debug({ title: 'Debug log server script', details: 'Server script added stylesheet' }); };