We have selected 10 modules that are frequently used in NetSuite’s SuiteScript 2.0 development and will introduce their uses and sample code. By utilizing these modules, you will be able to develop efficiently.
10 frequently used modules and how to use them
1. N/record module
Use:
This module is used to manipulate records. It is used to manipulate various NetSuite records, such as creating, searching, updating, and deleting records.使用します。
sample code:
var record = require('N/record');
// create a new customer record
var customerRecord = record.create({
type: record.Type.CUSTOMER
});
customerRecord.setValue({
fieldId: 'companyname', value: 'new customer name'
value: 'new customer name'
});
var recordId = customerRecord.save();
log.debug('Customer record ID:', recordId);
Description.:
This module makes it easy to manipulate records in NetSuite with methods such as create(), load(), delete(), and submit().
2. N/log module
Use:
This module is used to output log messages. It is useful for outputting messages during debugging and error handling.
sample code:
var log = require('N/log');
log.debug({
title: 'Processing started', details: 'Creating customer record'
details: 'Creating customer record'
});
Description.:
log.debug(), log.error(), etc. can be used to log the progress of a process or the contents of an error in a script. This is very useful for debugging.
Description: This module allows you to easily record in NetSuite.
3. N/search module
Use:
This module is designed to search for records in NetSuite. It uses filtering, aggregation, and sorting to efficiently retrieve data.取得できます。
sample code:
var search = require('N/search');
var customerSearch = search.create({such as.
type: search.Type.CUSTOMER,
columns: ['companyname'],
filters: [['companyname', 'is', 'customername']]
});
var results = customerSearch.run().getRange({ start: 0, end: 10 });
results.forEach(function(result) {)
log.debug('Customer name:', result.getValue('Company name')); log.debug('Customer name:', result.getValue('Company name'))
});Description:.
The N/search module allows you to search for records using specific criteria and retrieve the results. The search results can be used to perform various operations.
4. N/ui/serverWidget module
Use:
This module is used to create custom forms and sub-lists. It is used to customize the user interface.
Sample:
var serverWidget = require('N/ui/serverWidget');
var form = serverWidget.createForm({
title: 'Custom Form'; var form = serverWidget.createForm({ title: 'Custom Form'
});
form.addField({
id: 'custpage_text', type: serverWidget.
type: serverWidget.FieldType.TEXT, label: 'text field'
label: 'text field'
});
form.addSubmitButton({
label: 'submit'
});
context.response.writePage(form);
Description.:
The N/ui/serverWidget module is used to create custom forms and dashboard widgets. It allows for flexible customization of the NetSuite interface.
5. N/email module
Use:
This module is used to send emails. It is used to send reports and notifications via email.
Sample:
var email = require('N/email');
var runtime = require('N/runtime');
var email.send({
author: runtime.getCurrentUser().id, recipients: '', email.send({ author: runtime.getCurrentUser().id, recipients.
subject: 'Test email', body: 'This is a test email.
body: 'This is a test email.'
});
Description: The
The N/email module allows you to send email directly from your scripts. It is used for notifications, error reporting, and sending reports.
6. N/https module
Use:
This module is used to communicate with external HTTPS resources. It is used for interfacing with external APIs.
Sample:
var https = require('N/https');
var response = https.get({
url: 'https://api.example.com/data'
});
log.debug('response:', response.body);
Description:.
Used to work with an external HTTPS server, sending GET and POST requests to retrieve external data and send the results of processing.
7. N/runtime module
Use:
This module is used to obtain information about the script execution environment and the current user.
Sample:
var runtime = require('N/runtime');
log.debug('Script ID:', runtime.getCurrentScript().id);
log.debug('Current user ID:', runtime.getCurrentUser().id);
Description:.
While a script is running, you can get the script ID, user ID, and the remaining execution time of the script. This is useful for keeping track of the status of a script.
8. N/transaction module
Usage:
This module is used to manipulate transaction records. It is used to manipulate sales slips, purchase slips, etc.
Sample code:
var transaction = require('N/transaction');
var salesOrder = transaction.create(トランザクション.タイプ.SALES_ORDER)({)
type: transaction.Type.SALES_ORDER
});
salesOrder.setValue({
fieldId: 'entity'、
value: 12345 // 顧客ID
});
var orderId = salesOrder.save();
log.debug('orderID:', orderId);
Description:.
The N/transaction module creates, updates, and retrieves records related to transactions such as sales, purchases, and payments.
9. N/file module
Use:
File operations. Used to upload, download, and save files.存に使用します。
Sample:
var file = require('N/file');
// create a new file
var newFile = file.create({
name: 'sample.txt', fileType: file.
fileType: file.Type.PLAINTEXT, contents: 'This is a sample text file.
contents: 'This is a sample text file.'
});
newFile.folder = 123; // folder ID
var fileId = newFile.save();
log.debug('File ID:', fileId);
Description:
The N/file module is used to manipulate files within NetSuite. You can create, upload, save, and download files.
10. N/task module
Usage:
This module is used to manage scheduled tasks. Recurring and background tasks can be configured.
Sample code:
var task = require('N/task');
var scheduledTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: 'customscript_my_scheduled_script',
deploymentId: 'customdeploy_my_scheduled_deploy'
});
scheduledTask.submit();
Description:.
Used to create and manage scheduled tasks. This is useful for setting up processes that you want to run periodically in the background.
Module List
Module | Description |
---|---|
N/action | Manages actions, creating and managing actions that trigger specific processes. |
N/auth | Handles authentication of API requests and authentication information such as OAuth 2.0 |
N/cache | Manage data caching and improve performance. |
N/certificateControl | Manages certificates such as SSL certificates and encryption keys. |
N/commerces | eProvides e-commerce related functions to manage orders and manipulate product information. |
N/compress | Compresses and decompresses data. |
N/config | Manages script configuration information and makes it easy to manage necessary settings. |
N/crypto | Encrypts, signs, and verifies data. |
N/crypto/certificate | Processes encryption certificates and generates and verifies certificates. |
N/crypto/random | Generates cryptographically secure random data. |
N/currency | Performs currency-related processing, including currency conversion and currency code management. |
N/currentRecord | Module for accessing the currently operating record. |
N/dataset | Create and manage datasets. |
N/datasetLink | Manage links associated with a dataset. |
N/email | Send email and send notifications and reports via email. |
N/encode | Performs data encoding, such as Base64 encoding and URL encoding |
N/error | Performs error handling, creates error objects, and retrieves error details |
N/file | Performs operations such as uploading, downloading, and creating files |
N/format | Performs date, currency, and numeric formatting |
N/format/i18n | Converts date and number formats by region with multilingual support. |
N/http | Module for sending HTTP requests. |
N/https | HModule for secure communication to send HTTPS requests. |
N/https/clientCertificate | Use a client certificate when making HTTPS requests. |
N/keyControl | Manage API keys and encryption keys. |
N/llm | Module for processing related to natural language processing and machine learning. |
N/log | Log messages for debugging and error handling |
N/pgp | Encrypts and signs data using PGP encryption. |
N/piremoval | Efficiently delete records and transactions. |
N/plugin | Create and manage plug-ins to extend NetSuite functionality. |
N/portlet | Create custom portlets for dashboards. |
N/query | Create SQL-like queries to retrieve records and data. |
N/record | Create, update, and retrieve records. |
N/recordContext | retrieve context information related to a record |
N/redirect | Redirect a user to a specified URL. |
N/render | Convert a record or list to HTML or PDF and display it |
N/runtime | Retrieve script runtime environment information. |
N/scriptTypes/restlet | Create and manage RESTlet scripts. |
N/search | Search records in NetSuite and retrieve data by specifying conditions. |
N/sftp | Use SFTP to transfer files. |
N/sso | Manage single sign-on (SSO) and authenticate users. |
N/suiteAppInfo | Obtain SuiteApp information. |
N/task | Module to manage script tasks. |
N/task/accounting/recognition | Recognize accounting-related tasks. |
N/transaction | Creates, updates, and retrieves transactions. |
N/translation | Provides translation-related functions and performs localization processing |
N/uis | Provides user interface (UI) related functions |
N/url | Performs URL manipulation and generation |
N/util | Provides utility functions to streamline common processes |
N/workbook | Create and manage spreadsheets |
N/workflow | Creates and manages workflows to automate business processes |
N/xml | XParses, generates, and manipulates XML. |
Summary
Utilizing these modules will greatly streamline your development work on NetSuite. Please understand the characteristics of each module and use them in appropriate situations.