🔹 What are Script Parameters?
Script parameters let you make your SuiteScripts configurable without hardcoding values.
Examples:
- API credentials (username, token, secret)
- Default subsidiary or location IDs
- Threshold values (e.g., “minimum order amount”)
- Boolean switches (on/off feature flags)
Instead of rewriting your script, you add a parameter → deploy the script → set the parameter value in the deployment record.
🔹 Types of Parameters
When you define a parameter in your script record, you choose a type. Common ones:
- Text → strings like “sandbox” or “production”
- Integer → numbers like “10”
- Checkbox → true/false values
- Select → picklist linked to a NetSuite record (Customer, Account, Subsidiary, etc.)
- Date/DateTime → scheduling values
🔹 Accessing Script Parameters
SuiteScript gives you APIs in the N/runtime
module to get parameters:
runtime.getCurrentScript().getParameter({ name: 'custscript_myparam' })
- Always use the internal ID of the parameter (starts with
custscript_
).
🔹 Example 1 — Simple Text Parameter
Scenario: Add a parameter called custscript_api_url for your REST API endpoint.
/**
*@NApiVersion 2.1
*@NScriptType ScheduledScript
*/
define(['N/runtime'], (runtime) => {
const execute = () => {
try {
// 1) Get the current script context
const script = runtime.getCurrentScript();
// 2) Fetch parameter value by its internal ID
const apiUrl = script.getParameter({ name: 'custscript_api_url' });
// 3) Use parameter in logic (here we just log it)
log.debug('Configured API URL', apiUrl);
// In a real integration, you would make HTTP calls to this apiUrl
} catch (e) {
log.error('Error using script parameter', e.message);
}
};
return { execute };
});
đź’ˇ Explanation:
- In deployment, set the
custscript_api_url
to something likehttps://api.test.com
. - The script can run against different environments without code changes.
🔹 Example 2 — Integer Parameter for Batch Size
Scenario: Control how many records to process per run.
/**
*@NApiVersion 2.1
*@NScriptType ScheduledScript
*/
define(['N/runtime'], (runtime) => {
const execute = () => {
try {
const script = runtime.getCurrentScript();
// Get integer parameter
const batchSize = parseInt(script.getParameter({ name: 'custscript_batch_size' })) || 50;
log.debug('Batch Size', batchSize);
// Example: fetch that many results in search
// search.run().getRange({ start: 0, end: batchSize });
} catch (e) {
log.error('Error using batch size parameter', e.message);
}
};
return { execute };
});
đź’ˇ Explanation:
- Instead of hardcoding
50
, admin can set batch size in the deployment.
🔹 Example 3 — Checkbox Parameter
Scenario: Toggle between Sandbox Mode and Production Mode.
/**
*@NApiVersion 2.1
*@NScriptType ScheduledScript
*/
define(['N/runtime'], (runtime) => {
const execute = () => {
try {
const script = runtime.getCurrentScript();
// Checkbox parameters return "T" (true) or "F" (false)
const sandboxMode = script.getParameter({ name: 'custscript_sandbox_mode' }) === 'T';
if (sandboxMode) {
log.debug('Mode', 'Running in SANDBOX mode');
// Do test logic here
} else {
log.debug('Mode', 'Running in PRODUCTION mode');
// Do production logic here
}
} catch (e) {
log.error('Error using sandbox mode parameter', e.message);
}
};
return { execute };
});
đź’ˇ Explanation:
- Helps switch environments without editing the code.
🔹 Example 4 — Select Parameter (Record Reference)
Scenario: A script should always post to a specific Account (from Chart of Accounts).
/**
*@NApiVersion 2.1
*@NScriptType UserEventScript
*/
define(['N/runtime'], (runtime) => {
const beforeSubmit = (context) => {
try {
const script = runtime.getCurrentScript();
// Select parameter stores the internal ID of the chosen record
const defaultAccount = script.getParameter({ name: 'custscript_default_account' });
if (defaultAccount) {
const rec = context.newRecord;
rec.setValue({
fieldId: 'account',
value: defaultAccount
});
log.debug('Account Set', `Default account ${defaultAccount} applied`);
}
} catch (e) {
log.error('Error applying default account', e.message);
}
};
return { beforeSubmit };
});
đź’ˇ Explanation:
- The parameter type is Select → Account.
- Admin picks an Account in deployment.
- Script automatically applies it.
🔹 Best Practices
- Prefix internal IDs with
custscript_
for consistency. - Always validate parameter values (check for null/empty).
- Use parseInt/parseFloat for numeric params.
- Use
=== 'T'
for checkboxes. - Store credentials (API keys, secrets) in Script Parameters or NetSuite’s Credential fields, never in code.
- If parameter values differ per subsidiary or deployment, create multiple deployments with different values.
âś… Key Takeaway
Script Parameters make your SuiteScripts flexible and reusable. Instead of hardcoding, you configure values at deployment time — making it easier for admins to manage and developers to maintain.