Home Anatomy of SuiteScript: Introduction
Post
Cancel

Anatomy of SuiteScript: Introduction

Introduction

Welcome to the Anatomy of SuiteScript series! In this series, we will explore the fundamentals of SuiteScript, demonstrating how to create various types of scripts to automate tasks in NetSuite. We will cover common patterns and best practices for writing SuiteScript, with a primary focus on different script types and their common patterns. SuiteScript 2.1, the latest iteration, will be used throughout, allowing us to utilize ES6 features such as arrow functions, nullish coalescing, and optional chaining.

Please note that this series will not focus on the different APIs available in SuiteScript, such as N/search, N/record, N/file, etc. These topics will be covered in the upcoming SuiteScript API series. Below is an overview of the different script types we will discuss in this series:

User Event Scripts

User Event Scripts execute server-side logic when a record is created, edited, or deleted. For instance, to update a field on a sales order when an invoice is created from the sales order, you could use a User Event Script deployed to an invoice record. Note that User Event Scripts only run when server-side actions are performed, such as record submit or record load. User input in the UI is not considered a server-side action until the record is submitted to NetSuite.

Client Scripts

Client Scripts run client-side logic when a record is created or edited. They can respond to events such as user input in a field or button clicks. Common use cases for Client Scripts include:

  • Validating a field when a user enters a value
  • Populating default field values
  • Hiding or showing fields based on another field’s value
  • Conditionally changing a field’s value based on another field’s value

Suitelets

Suitelets are used to create web pages accessible in the NetSuite UI. Common use cases include:

  • Creating a highly customized UI for data entry or task execution in NetSuite
  • Custom reports, often powered by SuiteQL

Restlets

Restlets create REST API endpoints accessible from external applications. While NetSuite provides a REST API using SuiteTalk, Restlets enable customization to fit your needs. For example, you may want to perform additional logic in NetSuite when creating a record externally. Restlets support both GET and POST requests for interacting with the endpoint.

Scheduled Scripts

Scheduled Scripts run on a set schedule or manually from the UI for one-off tasks. User interaction is not required for these scripts.

Map/Reduce Scripts

Map/Reduce Scripts run on a schedule or when manually triggered. They are used for large-scale data processing on an input array. For example, if you need to update 25 work orders, a Scheduled Script could iterate over and update them one by one. With a Map/Reduce Script, you could pass in the 25 work orders as an input array, and the script would update them in parallel.

Note that the number of concurrent processes cannot exceed your license limit. If your license allows for 5 concurrent processes, NetSuite will create 5 work orders in parallel, then move on to the next 5.

Map/Reduce Scripts are complex, with multiple entry points.

Custom Module scripts

This script allows you to abstract common functionality into a module that can be used in other scripts. If my company has a complex company specific way of creating a sales order that I need to use in multiple scripts, I can create a custom module called companyTransactions that exports a function called createSalesOrder that can be used in multiple scripts.

Sometimes I will create custom modules just to organize my code in a single project.

Other Scripts

While the above scripts are the most common scripts, there are other scripts that can be used to accomplish various tasks.

Some of these scripts include:

  • Portlet Scripts - Used to create a custom portlet that can be added to a dashboard
  • GL Plug-in Scripts - Used to create a custom GL plug-in which can be used to create GL entries on a transaction
  • Mass Update Scripts - Used to create a custom mass update script that can be used to update multiple records at once

and others.

These scripts will not be covered in this series.

About this Series

Each script will have its own post. The posts will be written in the order of the scripts listed above.

Each post will discuss all the different entry points for the script. Some common patterns might be discussed. Sometimes we will finish by building an example script that may or may not use all the different entry points. SuiteQL will be featured heavily in this series; it is my current default for querying data in NetSuite.

For more information on SuiteQL, see my series on SuiteQL.

This post is licensed under CC BY 4.0 by the author.

SuiteQL Recipe: Work Order Variance

Anatomy of SuiteScript: Script Deconstruction