SlideShare a Scribd company logo
1 of 28
Download to read offline
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

What's hot

Basics of software engineering
Basics of software engineeringBasics of software engineering
Basics of software engineeringMadhav Suratkar
 
The Joy of SciPy
The Joy of SciPyThe Joy of SciPy
The Joy of SciPykammeyer
 
Frameworks de desenvolvimento web
Frameworks de desenvolvimento webFrameworks de desenvolvimento web
Frameworks de desenvolvimento webArlindo Santos
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaDate and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaEdureka!
 
Ebook ITIL Na Prática
Ebook ITIL Na PráticaEbook ITIL Na Prática
Ebook ITIL Na PráticaFernando Palma
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonMohammed Rafi
 
Qualidade de Software: Modelos e normas
Qualidade de Software: Modelos e normasQualidade de Software: Modelos e normas
Qualidade de Software: Modelos e normasAlex Camargo
 
Cuadro comparativo analis y diseño estructurado Y analisis orientado a objetos
Cuadro comparativo analis y diseño estructurado Y analisis orientado a objetosCuadro comparativo analis y diseño estructurado Y analisis orientado a objetos
Cuadro comparativo analis y diseño estructurado Y analisis orientado a objetosemilis
 
Áreas de Conhecimento da Engenharia de Software
Áreas de Conhecimento da Engenharia de SoftwareÁreas de Conhecimento da Engenharia de Software
Áreas de Conhecimento da Engenharia de SoftwareElaine Cecília Gatto
 
Python libraries for data science
Python libraries for data sciencePython libraries for data science
Python libraries for data sciencenilashri2
 

What's hot (20)

Python libraries
Python librariesPython libraries
Python libraries
 
Basics of software engineering
Basics of software engineeringBasics of software engineering
Basics of software engineering
 
What is Jupyter Notebook?
What is Jupyter Notebook?What is Jupyter Notebook?
What is Jupyter Notebook?
 
The Joy of SciPy
The Joy of SciPyThe Joy of SciPy
The Joy of SciPy
 
Frameworks de desenvolvimento web
Frameworks de desenvolvimento webFrameworks de desenvolvimento web
Frameworks de desenvolvimento web
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaDate and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
 
Ebook ITIL Na Prática
Ebook ITIL Na PráticaEbook ITIL Na Prática
Ebook ITIL Na Prática
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
 
Python network programming
Python   network programmingPython   network programming
Python network programming
 
Qualidade de Software: Modelos e normas
Qualidade de Software: Modelos e normasQualidade de Software: Modelos e normas
Qualidade de Software: Modelos e normas
 
Rup disciplinas
Rup disciplinasRup disciplinas
Rup disciplinas
 
Apostila ITIL
Apostila ITILApostila ITIL
Apostila ITIL
 
Metodología RUP
Metodología RUPMetodología RUP
Metodología RUP
 
Swebok final
Swebok finalSwebok final
Swebok final
 
Python introduction
Python introductionPython introduction
Python introduction
 
Cuadro comparativo analis y diseño estructurado Y analisis orientado a objetos
Cuadro comparativo analis y diseño estructurado Y analisis orientado a objetosCuadro comparativo analis y diseño estructurado Y analisis orientado a objetos
Cuadro comparativo analis y diseño estructurado Y analisis orientado a objetos
 
Áreas de Conhecimento da Engenharia de Software
Áreas de Conhecimento da Engenharia de SoftwareÁreas de Conhecimento da Engenharia de Software
Áreas de Conhecimento da Engenharia de Software
 
Python libraries for data science
Python libraries for data sciencePython libraries for data science
Python libraries for data science
 
Aplicaciones distribuidas
Aplicaciones distribuidasAplicaciones distribuidas
Aplicaciones distribuidas
 

Similar to Suite Script 2.0 API Basics

Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net FundamentalsLiquidHub
 
Nt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNicole Gomez
 
.NET Core Apps: Design & Development
.NET Core Apps: Design & Development.NET Core Apps: Design & Development
.NET Core Apps: Design & DevelopmentGlobalLogic Ukraine
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideMohanraj Thirumoorthy
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentationdharisk
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksSunil Patil
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworksSunil Patil
 
Operator SDK for K8s using Go
Operator SDK for K8s using GoOperator SDK for K8s using Go
Operator SDK for K8s using GoCloudOps2005
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notesWE-IT TUTORIALS
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java scriptmichaelaaron25322
 
Using advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint developmentUsing advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint developmentsadomovalex
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overviewskill-guru
 
Let’s template
Let’s templateLet’s template
Let’s templateAllenKao7
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2Long Nguyen
 

Similar to Suite Script 2.0 API Basics (20)

Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
Nt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language Analysis
 
.NET Core Apps: Design & Development
.NET Core Apps: Design & Development.NET Core Apps: Design & Development
.NET Core Apps: Design & Development
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentation
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source Frameworks
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
 
Operator SDK for K8s using Go
Operator SDK for K8s using GoOperator SDK for K8s using Go
Operator SDK for K8s using Go
 
.net Framework
.net Framework.net Framework
.net Framework
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java script
 
Using advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint developmentUsing advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint development
 
Angular 9
Angular 9 Angular 9
Angular 9
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
 
Spring boot
Spring bootSpring boot
Spring boot
 
Let’s template
Let’s templateLet’s template
Let’s template
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
React inter3
React inter3React inter3
React inter3
 

Recently uploaded

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

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!!!.