📑 In This Module
🎯 Learning Objectives
- Set up Eclipse IDE with SuiteCloud plugin
- Understand SuiteScript 2.0 file structure
- Write and deploy a Hello World script
- View script execution in the Execution Log
1. SuiteScript 2.0 Anatomy
Every SuiteScript 2.0 file has three required parts:
- Required Annotations — Tell NetSuite about your script
- Define Statement — Import modules and create your script module
- Entry Point Functions — The functions NetSuite will call
2. Required Annotations
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
Without these annotations, your script won't be recognized as SuiteScript 2.0!
| Annotation | Purpose | Values |
|---|---|---|
@NApiVersion | SuiteScript version | 2.0 or 2.1 |
@NScriptType | Script type | UserEventScript, ClientScript, ScheduledScript, etc. |
@NModuleScope | Module visibility (optional) | SameAccount, Public |
Version 2.1 supports modern JavaScript features like arrow functions, let/const, template literals, and promises. Use 2.1 for new development.
3. The Define Statement
The define statement imports NetSuite modules and creates your script module:
define(['N/record', 'N/log'], function(record, log) {
// Your code here
return {
afterSubmit: afterSubmit
};
});
How It Works
| Part | Purpose |
|---|---|
['N/record', 'N/log'] | Array of modules to import |
function(record, log) | Parameters that receive the imported modules |
return { ... } | Object mapping entry point names to functions |
The order of modules in the array must match the order of parameters in the function. If you import ['N/record', 'N/log'], your function must be function(record, log) — not function(log, record).
4. Entry Point Functions
Entry points are functions that NetSuite calls automatically when certain events occur:
function afterSubmit(context) {
log.debug('Title', 'Record saved successfully!');
}
Entry Points by Script Type
| Script Type | Entry Points |
|---|---|
| User Event | beforeLoad, beforeSubmit, afterSubmit |
| Client Script | pageInit, fieldChanged, validateField, saveRecord, etc. |
| Scheduled | execute |
| Map/Reduce | getInputData, map, reduce, summarize |
| Suitelet | onRequest |
| RESTlet | get, post, put, delete |
5. Development Workflow
The complete process to deploy a script:
- Write the Script — Create your .js file in Eclipse or any IDE
- Upload to File Cabinet — Put the file in SuiteScripts folder
- Create Script Record — Customization → Scripting → Scripts → New
- Create Deployment — Link script to specific records/triggers
- Test — Trigger the script and check Execution Log
The SuiteCloud IDE plugin automates uploading to File Cabinet. You can also manually upload via Documents → Files → File Cabinet → SuiteScripts.
6. Hello World Example
Here's a complete User Event script that logs a message after every record save:
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
* @description Hello World - logs after record save
*/
define(['N/log'], function(log) {
/**
* After the record is submitted to the database
* @param {Object} context
* @param {Record} context.newRecord - The saved record
* @param {string} context.type - Trigger type (create, edit, delete)
*/
function afterSubmit(context) {
log.debug({
title: 'Hello World',
details: 'Script executed! Trigger type: ' + context.type
});
}
return {
afterSubmit: afterSubmit
};
});
Viewing the Execution Log
After triggering your script, check the output:
- Go to Customization → Scripting → Script Deployments
- Click on your deployment
- Click the Execution Log subtab
- Look for your log messages
There are four log levels: log.debug(), log.audit(), log.error(), log.emergency(). Use debug for development, audit for important business events.
🏋️ Practice Exercises
Create a User Event script on the Employee record that logs the employee's name in afterSubmit. Deploy it and save an Employee to see the log.
Modify your script to also log in beforeSubmit. Compare what information is available in beforeSubmit vs afterSubmit.
Add logs at all four levels (debug, audit, error, emergency). Then change the deployment's Log Level setting and observe which logs appear.
🎯 Key Takeaways
- Every SuiteScript 2.0 needs annotations, define statement, and entry points
@NApiVersionand@NScriptTypeare required annotations- Use
define()to import modules and create your script - Module array order must match function parameter order
- Scripts must be uploaded to File Cabinet before deployment
- Create Script Record and Deployment to activate your script
- Check Execution Log to verify your script ran successfully