SPA Server Script Basic Examples using SuiteScript modules

The following example shows an SPA server script that loads the N/runtime Module to identify the current user and retrieve the user's email address. Then, it compares the current user email address with the specified email address in the code, and throws an error if the values don't match. When the error is thrown, a standard error message is shown in NetSuite with the specified message (for example, "Unauthorized user") and the SPA is not served.

           /**
 * @NApiVersion 2.1
 * @NScriptType SpaServerScript
 */
import runtime from 'N/runtime';
 
export const initializeSpa = (context) => {
    var currentUser = runtime.getCurrentUser();
    var userEmail = currentUser.email;          
    if (userEmail !== 'email@netsuite.com') {
        throw "Unauthorized user";
    }          
    return;
}; 

        

The following sample adds a custom.css style sheet, located in the folder <folder>/<assetsfolder>/css/.

          /**
 * @NApiVersion 2.1
 * @NScriptType SpaServerScript
 */

export const initializeSpa = (context) => {
    context.addStyleSheet({
        relativePath: "/css/custom.css" 
    });
    return;
}; 

        

Related Topics:

Developing Single Page Applications
Single Page Application Server Script

General Notices