SlideShare a Scribd company logo
SuiteScript 2.0 API
Netsuite
Released 2015 ∼
July 13, 2018
Agenda
NetSuite at a glance
What is SuiteScript API?
Key concepts of SuiteScript 2.0 API
SuiteScript 2.0 Syntax
HelloWorld Script
Advantages of SuiteScript 2.0
Drawback
Coexistence rules
1
Objectives of this presentation
Understanding the basics of SuiteScript 2.0 API
Explore the key differences between SuiteScript 1.0 & SuiteScript 2.0
2
NetSuite at a glance
Cloud-based business management software
Software as a Service (SaaS)
3
Is a JavaScript API that offers a broad range of options
for enhancing and extending NetSuite
SuiteScript API
What is SuiteScript API?
😟 😎 4
Key Concepts
of
SuiteScript 2.0
5
SuiteScript 2.0 is modular
All SuiteScript 2.0 APIs are organized into modules
Each module reflects the functionality
Concept #1:
6
NetSuite modules & objects
record searchlog file
NS
N
create({}) save({})load({})
∼32 modules
e.g: N/file
∼… APIs
e.g: record.create({});
setValue({}) …({})
Concept #1 (cont’d)
7
Module must be explicitly loaded by a script before using that module’s API
Suitescript 1.0 API
Organized in a Single global library JavaScript file.
Each file gets loaded to every single script regardless of how much API the script use.
Suitescript 2.0 API
Organized and grouped into the modules
Modules are loaded only when they are needed. — based on Asynchronous
Module Definition(AMD)
Now
Before
Modular
Concept #1 (cont’d)
8
Object as Arguments
The arguments passed to methods are typically {key:value} objects
var myObject = {
fieldId: 'greetingMsg',
value: 'Hello, World!'
};
myRecord.setValue(myObject);
myRecord.setValue({
fieldId: 'greetingMsg',
value: ‘Hello, World!'
});
Concept #2:
9
Suitescript 1.0 API
Argument list
Suitescript 2.0 API
Object as argument
Now
Before
‣ Objects
var myObject = {
fieldId: 'greetingMsg',
value: 'Hello, World!'
};
myRecord.setValue(myObject);
nlapiSetFieldValue('greetingMsg', 'Hello, World!');
Concept #2 (cont’d)
10
Script types and their Entry pointsConcept #3:
Script type:
SuiteScript 2.0 scripts consist of several script types
Each script type is designed for a specific type of situation and specific
types of triggering events
Entry point:
Represents the juncture at which the system grants control of the NetSuite application to
the script.
Each script type includes one or more entry points that are exclusive to that type
11
UserEventScript
ClientScript
ScheduledScript
…
Server
(execute on the server)
Client
(execute in the user’s
browser)
Script types Entry points
✦ beforeLoad
✦ beforeSubmit
✦ afterSubmit
✦ execute
✦ fieldChange
✦ pageInit
✦ Etc…
Concept #3 (cont’d)
12
…
Suitescript 1.0 API
Scripts are not Expressive: - hard to recognize the purpose of a script
Scripts are Dependent: - Actions depend on settings done on NetSuite side
Suitescript 2.0 API
Expressive scripts - automatically detected by NetSuite
Independent scripts - No other enhancements needed.
Now
Before
‣ JSDocs tags
‣ Script types & Entry points
function myFunction(){
// logic here
}
sample_script.js
/**
* @NScriptType <script_type_name>
*/
define([], function() {
function myFunction(){
// logic here
}
return {

<entry_point_name> : <entry_point_function>

};
});
sample_script.js
Concept #3 (cont’d)
13
Entry point scripts & Custom module scriptsKey concept #4:
Entry point script:
The primary script attached on the script record
It identifies the script type, entry points, and entry point functions
Each entry point script must include at least one entry point and entry point function
Custom module script:
Is a user-defined script that holds the logic that can be used by other scripts
It’s loaded by an Entry point script as a dependency
Script type(s) declaration is not required
14
Suitescript 1.0 API
Suitescript 2.0 APINow
Before
NS
Script record A Script record B
script_A.js script_B.jsscript_A.js script_B.js
NS
Script record A Script record B
script_A.js script_B.js
‣ Custom module scripts
Concept #4 (cont’d)
15
Same modules used by-
many script records
Anatomy of an Entry Point Script
/**
* @NApiVersion 2.0
* @NScriptType UserEventScript
*/
define(['N/record', 'N/ui/dialog'],
function(record, dialog) {
function doBeforeLoad() {
/* logic of function*/
}
function doBeforeSubmit() {
/* logic of function*/
}
function doAfterSubmit() {
/* logic of function*/
}
return {
beforeLoad : doBeforeLoad,
beforeSubmit: doBeforeSubmit,
afterSubmit : doAfterSubmit,
};
}
);
JSDoc tags:
Required for an entry point script
Entry points:
At least one STANDARD entry point is required for
a script type
Define’s first argument:
List of Dependencies and/or Modules
3
2
1
4
Define’s second argument:
Callback function
1.
2.
3.
4.
Concept #4 (cont’d)
16
Anatomy of a Custom Module Script
JSDoc tags:
NOT Required for a custom module script, but USEFUL.
Entry point:
At least one USER-DEFINED entry point is required for a
custom module
Define’s first argument:
List of Dependencies and/or Modules required by the script
/**
* fileName.js
* @NApiVersion 2.x
* @ModuleScope Public
*/
define(['N/record', ’N/search'],
function(record, search) {
function dummySearch() {
/* logic of function*/
}
return {
myDummySearch : dummySearch,
};
}
);
3
2
1
4
Define’s second argument:
Callback function
1.
2.
3.
4.
Concept #4 (cont’d)
17
Syntax
18
SuiteScript 2.0 Syntax
SuiteScript 2.0 syntax == JavaScript Syntax
๏ SuiteScript 2.0 methods takes plain JavaScript key/value object as an input.
๏ All boolean values take true or false (not T or F respectively)
๏ Parameter types in SuiteScript 2.0 must match as those listed in the Docs/NetSuite help
๏ Enumeration encapsulated common constants (e.g; standard record types)
๏ Sublists and column indexing begins at 0 (not 1)
… except some rules:
19
Let’s create a simple entry point script:
✓ Shows a message on page load
/**
* @NApiVersion 2.0
* @NScriptType ClientScript
*
*/
define([ 'N/ui/message' ], function(message) {
function showMessage() {
var msgObj = message.create({
title : 'Greeting',
message : 'Hello, welcome!',
type : message.Type.INFORMATION,
});
msgObj.show();
}
return {
pageInit : showMessage,
};
});
• Q: Why a Script Type is ClientScript ?
• Q: What is the name of an entry point
in this script ?
A: “shows a message on page”
(does something on a page)
A: “pageInit”
• Q: What is the name of an entry point
function in this script ?
A: “showMessage”
20
Advantages
and
Drawback
21
Some Advantages of SuiteScript 2.0
Enables us to create our own custom modules
✓ Keeps code DRY (Don’t Repeat Yourself): - One module used by many scripts!!
✓ Abstraction : - Later changes don’t affect the deployed script(s)
✓ Possible to add those modules to SuiteApps and expose them to third parties.
Modern programming syntax and behavior
✓ Modeled to behave and look like modern JavaScript — e.g: No nlapi/nlobj prefix
✓ Third party JavaScript API support
✓ Updated sublist and column indexing — (begins at 0 instead of 1)
Functionality enhancements
✓ MapReduce script type : designed to handle large amounts of data.
‣ automatic yielding without disruption to the script
Automatic Dependency management: No need to remember to order of library files
22
Other Advantages of SuiteScript 2.0
Easier to catch-up for non-NetSuite programmers
Easier to upgrade for future versions: easy as changing the
version number
Good and solid documentation with adequate examples
SuiteScript 2.0 the way forward
23
Optional parameters
[e.g; setAge(age = 18)]
Drawback
JavaScript SuiteScript 2.0
Arrow functions
[e.g; (a, b) => a + b;]
Rest parameters
[e.g; avgAge(…age)]
Block-scoped variables
[ e.g; let age = 18; ]
Mismatching of Scripting-language specification:
- JavaScript’s new version is ECMAScript 8 (partially supported), but SuiteScript 2.0 currently
supports ECMAScript 5
There’s a workaround here!, but haven’t tried it yet!! 24
Ex.:
Coexistence rules
1. SuiteScript 1.0 and 2.0 cannot intermix within the same script
‣ You cannot use 2.0 modules as 1.0 Library scripts
‣ You cannot include 1.0 files as 2.0 dependencies
2. The two versions can intermix in the same account, in the same
application, and can even be deployed on the same record.
SuiteScript 1.0 is still supported. however…
25
…however, SuiteScript 1.0 can be deprecated anytime!!!.
Reference
NetSuite Help Center
https://stoic.software/effective-suitescript/2-ss2-
modules/
26
SuiteScript 2.0 API - Documentation
Thank you

More Related Content

ODP
Virtual Hosts Configuration with Weblogic Server
DOC
Analyzing awr report
PDF
Repository and Unit Of Work Design Patterns
PDF
Alphorm.com Formation Microsoft Azure (AZ-500) : Sécurité
PPTX
Chef fundamentals
PPTX
Resiliency vs High Availability vs Fault Tolerance vs Reliability
PDF
AV/DF Advanced Security Option
PPTX
Cassandra Performance and Scalability on AWS
Virtual Hosts Configuration with Weblogic Server
Analyzing awr report
Repository and Unit Of Work Design Patterns
Alphorm.com Formation Microsoft Azure (AZ-500) : Sécurité
Chef fundamentals
Resiliency vs High Availability vs Fault Tolerance vs Reliability
AV/DF Advanced Security Option
Cassandra Performance and Scalability on AWS

What's hot (20)

DOCX
Content server installation guide
PPTX
Stephane Lapointe: Governance in Azure, keep control of your environments
PPTX
Azure Automation and Update Management
PPTX
20220302_TechDojo_OpenShift_BootCamp_1章概要
PPTX
Part 01: Azure Virtual Networks – An Overview
PPTX
Virtualization 101: Everything You Need To Know To Get Started With VMware
PPTX
PDF
Microservices for Application Modernisation
PPTX
Introduction to Docker - 2017
PPTX
AlwaysON Basics
PPTX
Azure cloud governance deck
PDF
Azure fundamentals
PPTX
Docker & Kubernetes 기초 - 최용호
ODP
Kubernetes Architecture
PPTX
Azure kubernetes service (aks)
PPTX
Understanding Azure Disaster Recovery
PDF
Docker and the Linux Kernel
PDF
SpringOne Tour: Spring Boot 3 and Beyond
PDF
ECS19 Elio Struyf - Setting Up Your SPFx CI/CD pipelines on Azure DevOps
PPTX
Domain Driven Design Quickly
Content server installation guide
Stephane Lapointe: Governance in Azure, keep control of your environments
Azure Automation and Update Management
20220302_TechDojo_OpenShift_BootCamp_1章概要
Part 01: Azure Virtual Networks – An Overview
Virtualization 101: Everything You Need To Know To Get Started With VMware
Microservices for Application Modernisation
Introduction to Docker - 2017
AlwaysON Basics
Azure cloud governance deck
Azure fundamentals
Docker & Kubernetes 기초 - 최용호
Kubernetes Architecture
Azure kubernetes service (aks)
Understanding Azure Disaster Recovery
Docker and the Linux Kernel
SpringOne Tour: Spring Boot 3 and Beyond
ECS19 Elio Struyf - Setting Up Your SPFx CI/CD pipelines on Azure DevOps
Domain Driven Design Quickly
Ad

Similar to Suite Script 2.0 API Basics (20)

PPTX
Web Techdfasvfsvgsfgnolofgdfggy Unit I.pptx
PDF
Dot Net Fundamentals
PPT
Asp.net mvc
PDF
Nt1310 Unit 3 Language Analysis
PPT
.NET Core Apps: Design & Development
ODP
Developing Microservices using Spring - Beginner's Guide
PPTX
Angularjs2 presentation
PPT
D22 portlet development with open source frameworks
PPT
D22 Portlet Development With Open Source Frameworks
PDF
Operator SDK for K8s using Go
PPTX
.net Framework
PDF
tybsc it asp.net full unit 1,2,3,4,5,6 notes
PPTX
Typescript language extension of java script
PPTX
Migrating to the Isolated worker process in Azure Functions .pptx
PPTX
Using advanced C# features in Sharepoint development
PPTX
Angular 9
PDF
.NET Portfolio
PPT
Struts 2 Overview
PPTX
PDF
Let’s template
Web Techdfasvfsvgsfgnolofgdfggy Unit I.pptx
Dot Net Fundamentals
Asp.net mvc
Nt1310 Unit 3 Language Analysis
.NET Core Apps: Design & Development
Developing Microservices using Spring - Beginner's Guide
Angularjs2 presentation
D22 portlet development with open source frameworks
D22 Portlet Development With Open Source Frameworks
Operator SDK for K8s using Go
.net Framework
tybsc it asp.net full unit 1,2,3,4,5,6 notes
Typescript language extension of java script
Migrating to the Isolated worker process in Azure Functions .pptx
Using advanced C# features in Sharepoint development
Angular 9
.NET Portfolio
Struts 2 Overview
Let’s template
Ad

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
A Presentation on Artificial Intelligence
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPT
Teaching material agriculture food technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Machine learning based COVID-19 study performance prediction
PDF
A comparative analysis of optical character recognition models for extracting...
MYSQL Presentation for SQL database connectivity
Review of recent advances in non-invasive hemoglobin estimation
A Presentation on Artificial Intelligence
sap open course for s4hana steps from ECC to s4
Chapter 3 Spatial Domain Image Processing.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Teaching material agriculture food technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
The AUB Centre for AI in Media Proposal.docx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Big Data Technologies - Introduction.pptx
Programs and apps: productivity, graphics, security and other tools
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Per capita expenditure prediction using model stacking based on satellite ima...
“AI and Expert System Decision Support & Business Intelligence Systems”
Machine learning based COVID-19 study performance prediction
A comparative analysis of optical character recognition models for extracting...

Suite Script 2.0 API Basics

  • 1. SuiteScript 2.0 API Netsuite Released 2015 ∼ July 13, 2018
  • 2. Agenda NetSuite at a glance What is SuiteScript API? Key concepts of SuiteScript 2.0 API SuiteScript 2.0 Syntax HelloWorld Script Advantages of SuiteScript 2.0 Drawback Coexistence rules 1
  • 3. Objectives of this presentation Understanding the basics of SuiteScript 2.0 API Explore the key differences between SuiteScript 1.0 & SuiteScript 2.0 2
  • 4. NetSuite at a glance Cloud-based business management software Software as a Service (SaaS) 3
  • 5. Is a JavaScript API that offers a broad range of options for enhancing and extending NetSuite SuiteScript API What is SuiteScript API? 😟 😎 4
  • 7. SuiteScript 2.0 is modular All SuiteScript 2.0 APIs are organized into modules Each module reflects the functionality Concept #1: 6
  • 8. NetSuite modules & objects record searchlog file NS N create({}) save({})load({}) ∼32 modules e.g: N/file ∼… APIs e.g: record.create({}); setValue({}) …({}) Concept #1 (cont’d) 7 Module must be explicitly loaded by a script before using that module’s API
  • 9. Suitescript 1.0 API Organized in a Single global library JavaScript file. Each file gets loaded to every single script regardless of how much API the script use. Suitescript 2.0 API Organized and grouped into the modules Modules are loaded only when they are needed. — based on Asynchronous Module Definition(AMD) Now Before Modular Concept #1 (cont’d) 8
  • 10. Object as Arguments The arguments passed to methods are typically {key:value} objects var myObject = { fieldId: 'greetingMsg', value: 'Hello, World!' }; myRecord.setValue(myObject); myRecord.setValue({ fieldId: 'greetingMsg', value: ‘Hello, World!' }); Concept #2: 9
  • 11. Suitescript 1.0 API Argument list Suitescript 2.0 API Object as argument Now Before ‣ Objects var myObject = { fieldId: 'greetingMsg', value: 'Hello, World!' }; myRecord.setValue(myObject); nlapiSetFieldValue('greetingMsg', 'Hello, World!'); Concept #2 (cont’d) 10
  • 12. Script types and their Entry pointsConcept #3: Script type: SuiteScript 2.0 scripts consist of several script types Each script type is designed for a specific type of situation and specific types of triggering events Entry point: Represents the juncture at which the system grants control of the NetSuite application to the script. Each script type includes one or more entry points that are exclusive to that type 11
  • 13. UserEventScript ClientScript ScheduledScript … Server (execute on the server) Client (execute in the user’s browser) Script types Entry points ✦ beforeLoad ✦ beforeSubmit ✦ afterSubmit ✦ execute ✦ fieldChange ✦ pageInit ✦ Etc… Concept #3 (cont’d) 12 …
  • 14. Suitescript 1.0 API Scripts are not Expressive: - hard to recognize the purpose of a script Scripts are Dependent: - Actions depend on settings done on NetSuite side Suitescript 2.0 API Expressive scripts - automatically detected by NetSuite Independent scripts - No other enhancements needed. Now Before ‣ JSDocs tags ‣ Script types & Entry points function myFunction(){ // logic here } sample_script.js /** * @NScriptType <script_type_name> */ define([], function() { function myFunction(){ // logic here } return {
 <entry_point_name> : <entry_point_function>
 }; }); sample_script.js Concept #3 (cont’d) 13
  • 15. Entry point scripts & Custom module scriptsKey concept #4: Entry point script: The primary script attached on the script record It identifies the script type, entry points, and entry point functions Each entry point script must include at least one entry point and entry point function Custom module script: Is a user-defined script that holds the logic that can be used by other scripts It’s loaded by an Entry point script as a dependency Script type(s) declaration is not required 14
  • 16. Suitescript 1.0 API Suitescript 2.0 APINow Before NS Script record A Script record B script_A.js script_B.jsscript_A.js script_B.js NS Script record A Script record B script_A.js script_B.js ‣ Custom module scripts Concept #4 (cont’d) 15 Same modules used by- many script records
  • 17. Anatomy of an Entry Point Script /** * @NApiVersion 2.0 * @NScriptType UserEventScript */ define(['N/record', 'N/ui/dialog'], function(record, dialog) { function doBeforeLoad() { /* logic of function*/ } function doBeforeSubmit() { /* logic of function*/ } function doAfterSubmit() { /* logic of function*/ } return { beforeLoad : doBeforeLoad, beforeSubmit: doBeforeSubmit, afterSubmit : doAfterSubmit, }; } ); JSDoc tags: Required for an entry point script Entry points: At least one STANDARD entry point is required for a script type Define’s first argument: List of Dependencies and/or Modules 3 2 1 4 Define’s second argument: Callback function 1. 2. 3. 4. Concept #4 (cont’d) 16
  • 18. Anatomy of a Custom Module Script JSDoc tags: NOT Required for a custom module script, but USEFUL. Entry point: At least one USER-DEFINED entry point is required for a custom module Define’s first argument: List of Dependencies and/or Modules required by the script /** * fileName.js * @NApiVersion 2.x * @ModuleScope Public */ define(['N/record', ’N/search'], function(record, search) { function dummySearch() { /* logic of function*/ } return { myDummySearch : dummySearch, }; } ); 3 2 1 4 Define’s second argument: Callback function 1. 2. 3. 4. Concept #4 (cont’d) 17
  • 20. SuiteScript 2.0 Syntax SuiteScript 2.0 syntax == JavaScript Syntax ๏ SuiteScript 2.0 methods takes plain JavaScript key/value object as an input. ๏ All boolean values take true or false (not T or F respectively) ๏ Parameter types in SuiteScript 2.0 must match as those listed in the Docs/NetSuite help ๏ Enumeration encapsulated common constants (e.g; standard record types) ๏ Sublists and column indexing begins at 0 (not 1) … except some rules: 19
  • 21. Let’s create a simple entry point script: ✓ Shows a message on page load /** * @NApiVersion 2.0 * @NScriptType ClientScript * */ define([ 'N/ui/message' ], function(message) { function showMessage() { var msgObj = message.create({ title : 'Greeting', message : 'Hello, welcome!', type : message.Type.INFORMATION, }); msgObj.show(); } return { pageInit : showMessage, }; }); • Q: Why a Script Type is ClientScript ? • Q: What is the name of an entry point in this script ? A: “shows a message on page” (does something on a page) A: “pageInit” • Q: What is the name of an entry point function in this script ? A: “showMessage” 20
  • 23. Some Advantages of SuiteScript 2.0 Enables us to create our own custom modules ✓ Keeps code DRY (Don’t Repeat Yourself): - One module used by many scripts!! ✓ Abstraction : - Later changes don’t affect the deployed script(s) ✓ Possible to add those modules to SuiteApps and expose them to third parties. Modern programming syntax and behavior ✓ Modeled to behave and look like modern JavaScript — e.g: No nlapi/nlobj prefix ✓ Third party JavaScript API support ✓ Updated sublist and column indexing — (begins at 0 instead of 1) Functionality enhancements ✓ MapReduce script type : designed to handle large amounts of data. ‣ automatic yielding without disruption to the script Automatic Dependency management: No need to remember to order of library files 22
  • 24. Other Advantages of SuiteScript 2.0 Easier to catch-up for non-NetSuite programmers Easier to upgrade for future versions: easy as changing the version number Good and solid documentation with adequate examples SuiteScript 2.0 the way forward 23
  • 25. Optional parameters [e.g; setAge(age = 18)] Drawback JavaScript SuiteScript 2.0 Arrow functions [e.g; (a, b) => a + b;] Rest parameters [e.g; avgAge(…age)] Block-scoped variables [ e.g; let age = 18; ] Mismatching of Scripting-language specification: - JavaScript’s new version is ECMAScript 8 (partially supported), but SuiteScript 2.0 currently supports ECMAScript 5 There’s a workaround here!, but haven’t tried it yet!! 24 Ex.:
  • 26. Coexistence rules 1. SuiteScript 1.0 and 2.0 cannot intermix within the same script ‣ You cannot use 2.0 modules as 1.0 Library scripts ‣ You cannot include 1.0 files as 2.0 dependencies 2. The two versions can intermix in the same account, in the same application, and can even be deployed on the same record. SuiteScript 1.0 is still supported. however… 25 …however, SuiteScript 1.0 can be deprecated anytime!!!.