SuiteScript 2.1 Custom Tool Script Type Code Samples
This sample consists of the three requirements for building a custom tool: a custom tool script, a JSON file for the schema, and the SDF object file. The custom tool script defines two tool methods: add() and reverseText(). The add() tool method takes two parameters and returns their sum. The reverseText() method takes a string and returns the reversed string. Together, these files show how to structure your custom tool before deployment to your NetSuite account.
You can find complete SuiteApp and ACP sample implementations in the MCP-Sample-Tools directory of the SuiteCloud Project Repository on Oracle Samples GitHub. This directory provides the source implementation for both the MCP Sample Tools SuiteApp and its ACP version.
Implementation of Custom Tools That Adds Numbers and Reverses a String
The following sample is a custom tool script that implements two tools: one for adding two numbers, and another for reversing a string.
This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects.
This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.
/**
* exampletools.jsc
* @NApiVersion 2.1
* @NModuleScope Public
*/
define([], function() {
return {
add: function (args) {
let a = args["a"];
let b = args["b"];
return a+b;
},
reverseText: function (args) {
let text = args["text"];
return text.split('').reverse().join('');
}
}
});
Custom Tool Definition Schema
The following sample is the JSON schema definition for the custom tools defined in the script. For more information about the properties of the JSON schema, see Custom Tool Script Requirements.
{
"tools": [
{
"name": "add",
"description": "Add two numbers together",
"inputSchema": {
"type": "object",
"properties": {
"a": { "type": "number", "description": "First addend" },
"b": { "type": "number", "description": "Second addend" }
},
"required": ["a", "b"]
},
"annotations": {
"title": "Add Numbers",
"readOnlyHint": true,
"idempotentHint": true,
"openWorldHint": false
}
},
{
"name": "reverseText",
"description": "Reverses a given text string. Example: if the user says 'Reverse the text: I like apples', call this tool with { \"text\": \"I like apples\" }. ",
"inputSchema": {
"type": "object",
"properties": {
"text": { "type": "string", "description": "Text to reverse" }
},
"required": ["text"]
},
"annotations": {
"title": "Reverse Text",
"readOnlyHint": true,
"idempotentHint": true,
"openWorldHint": false
}
}
]
}
Custom Tool SDF XML Object
The following sample is the SDF XML for the custom tool.
<tool scriptId=customtool_test1">
<name>Test Agent Tool 1</name>
<scriptfile>[/SuiteApps/com.netsuite.tools/tools/scriptfile.js]</scriptfile>
<rpcschema>[/SuiteApps/com.netsuite.tools/tools/scriptfile_schema.json]</rpcschema>
<exposeto3rdpartyagent>T</exposeto3rdpartyagent>
<permissions>
<permission>
<permkey>LIST_EMAILTEMPLATE</permkey>
<permlevel>FULL</permlevel>
</permission>
<permission>
<permkey>ADMI_CRMLIST</permkey>
<permlevel>VIEW</permlevel>
</permission>
</permissions>
</tool>