NetSuite SuiteScript 2.0 10 most frequently used modules for development and how to use them

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

ModuleDescription
N/actionManages actions, creating and managing actions that trigger specific processes.
N/authHandles authentication of API requests and authentication information such as OAuth 2.0
N/cacheManage data caching and improve performance.
N/certificateControlManages certificates such as SSL certificates and encryption keys.
N/commerceseProvides e-commerce related functions to manage orders and manipulate product information.
N/compressCompresses and decompresses data.
N/configManages script configuration information and makes it easy to manage necessary settings.
N/cryptoEncrypts, signs, and verifies data.
N/crypto/certificateProcesses encryption certificates and generates and verifies certificates.
N/crypto/randomGenerates cryptographically secure random data.
N/currencyPerforms currency-related processing, including currency conversion and currency code management.
N/currentRecordModule for accessing the currently operating record.
N/datasetCreate and manage datasets.
N/datasetLinkManage links associated with a dataset.
N/emailSend email and send notifications and reports via email.
N/encodePerforms data encoding, such as Base64 encoding and URL encoding
N/errorPerforms error handling, creates error objects, and retrieves error details
N/filePerforms operations such as uploading, downloading, and creating files
N/formatPerforms date, currency, and numeric formatting
N/format/i18nConverts date and number formats by region with multilingual support.
N/httpModule for sending HTTP requests.
N/httpsHModule for secure communication to send HTTPS requests.
N/https/clientCertificateUse a client certificate when making HTTPS requests.
N/keyControlManage API keys and encryption keys.
N/llmModule for processing related to natural language processing and machine learning.
N/logLog messages for debugging and error handling
N/pgpEncrypts and signs data using PGP encryption.
N/piremovalEfficiently delete records and transactions.
N/pluginCreate and manage plug-ins to extend NetSuite functionality.
N/portletCreate custom portlets for dashboards.
N/queryCreate SQL-like queries to retrieve records and data.
N/recordCreate, update, and retrieve records.
N/recordContextretrieve context information related to a record
N/redirectRedirect a user to a specified URL.
N/renderConvert a record or list to HTML or PDF and display it
N/runtimeRetrieve script runtime environment information.
N/scriptTypes/restletCreate and manage RESTlet scripts.
N/searchSearch records in NetSuite and retrieve data by specifying conditions.
N/sftpUse SFTP to transfer files.
N/ssoManage single sign-on (SSO) and authenticate users.
N/suiteAppInfoObtain SuiteApp information.
N/taskModule to manage script tasks.
N/task/accounting/recognitionRecognize accounting-related tasks.
N/transactionCreates, updates, and retrieves transactions.
N/translationProvides translation-related functions and performs localization processing
N/uisProvides user interface (UI) related functions
N/urlPerforms URL manipulation and generation
N/utilProvides utility functions to streamline common processes
N/workbookCreate and manage spreadsheets
N/workflowCreates and manages workflows to automate business processes
N/xmlXParses, 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.