Custom Tool Script for Number Addition and String Reversal in
Starting in NetSuite 2026.1, a new custom tool script enables addition of numbers and reversal of strings using SuiteScript 2.1.
Starting in NetSuite 2026.1, a new custom tool script is introduced that allows developers to implement functionality for adding two numbers and reversing a string. This enhancement is especially useful for developers looking to create efficient scripts that execute multiple operations with minimal overhead.
Overview of the Custom Tool Script
The custom tool script sample consists of two primary functions:
- Addition: Adds two numbers provided as arguments.
- String Reversal: Reverses a string input.
This sample utilizes SuiteScript 2.1's define function, imperative for defining entry point scripts that can be deployed and attached to script records. This structure aligns with modern practices in NetSuite development, ensuring scripts are modular and re-usable.
Script Details
Here’s a breakdown of the script content:
/**
* exampletools.js
* @NApiVersion 2.1
* @NModuleScope Public
* @NScriptType CustomTool
*/
define([], function() {
return {
add: async function (args) {
try {
const a = args["a"];
const b = args["b"];
return {
result: a + b
};
} catch(e) {
return {
result: "",
error: "There was an error executing the tool: " + e
};
}
},
reverseText: async function (args) {
try {
const text = args["text"];
return {
result: text.split('').reverse().join('')
};
} catch(e) {
return {
result: "",
error: "There was an error executing the tool: " + e
};
}
}
}
});
Important Notes
- Error Handling: Each method has robust error handling to ensure that potential issues do not disrupt the execution of the script. Developers should consider extending error messages to capture more context as necessary.
- Module Imports: Although the script does not import specific modules, it’s advisable to import modules like
N/logandN/utilwhen utilizing their functionalities. This practice ensures better management of dependencies and reduces issues related to module availability.
Who This Affects
This new feature is particularly relevant for:
- Developers: Who will implement and maintain custom scripts.
- Administrators: Overseeing the deployment and usage of these tools within the organization.
Key Takeaways
- The custom tool script for adding numbers and reversing strings is newly available in SuiteScript 2.1 starting from NetSuite 2026.1.
- It demonstrates the use of asynchronous functions and error handling in operation.
- Developers should always incorporate necessary module imports to enhance script reliability.
- Utilizing modern JavaScript features can improve script performance and readability.
Weekly Update History (1)
CustomTool is now supported in the @NScriptType JSdoc tag and must be included in the headers of Custom Tool scripts. Updated the information in the following help topics: SuiteScript 2.1 Custom Tool Script Type Code Samples SuiteScript 2.x JSDoc Tags Required JSDoc Tags for Entry Point Scripts
View Oracle DocsWas this article helpful?