When a script uses values that may change over time, it is usually better to control those values through script parameters instead of hardcoding them directly in the script.
Script parameters allow administrators to update certain script values from the script deployment without editing the script file.
Scenario
A script needs to use values that may change depending on the business process.
Examples may include:
- default status
- saved search ID
- employee reviewer
- email recipient
- number of days before follow-up
- processing limit
- custom record type reference
If these values are hardcoded, a developer may need to edit and redeploy the script each time the value changes.
Solution
Use script parameters to store values that administrators may need to control.
This makes the script more flexible and easier to maintain.
Instead of placing the value directly in the script, the script reads the value from the script deployment.
Common Script Parameter Examples
- Saved Search ID – Allows admins to change which saved search the script uses.
- Default Status – Allows admins to control what status the script applies.
- Email Recipient – Allows admins to update notification recipients without editing code.
- Processing Limit – Allows admins to control how many records the script processes.
- Follow-Up Days – Allows admins to adjust date logic without script changes.
Sample Syntax
The sample below shows how a script can read parameter values from the script deployment.
/**
* @NApiVersion 2 .1
* @NScriptType ScheduledScript
*/
define(['N/runtime', 'N/log'], (runtime, log) => {
function execute(context) {
const script = runtime.getCurrentScript();
const savedSearchId = script.getParameter({
name: 'custscript_saved_search_id'
});
const processingLimit = script.getParameter({
name: 'custscript_processing_limit'
});
log.audit({
title: 'Script Parameters',
details: {
savedSearchId,
processingLimit
}
});
// Add script processing logic here.
}
return {
execute
};
});
How It Works
The script uses:
runtime.getCurrentScript()
to access the current script execution.
Then it uses:
script.getParameter({
name: 'custscript_saved_search_id'
});
to read the parameter value from the script deployment.
The parameter ID must match the script parameter ID configured in NetSuite.
Where to Set Script Parameters
Script parameters are configured on the script record or script deployment.
The general setup is:
- Open the script record.
- Add the needed parameter.
- Set the parameter ID.
- Open the script deployment.
- Enter the value the script should use.
Netsuite:
Go to: Customization > Scripting > Scripts > New or Find existing script you need set parameters > Parameters subtab
If you have an existing deployment > Go to: Customization > Scripting > Script Deployment > Find existing script deployment > Parameters subtab > set parameters
If it’s for a new script click Deploy Script > it will redirect you to new script deployment
Netsuite Next:
Open the Explore menu (hamburger icon in the bottom left corner beside the home button). In the menu, go to Customization > Scripting > Scripts. Then, on the next page, New Script or click existing Script > Parameters subtab
If you have an existing deployment > Open the Explore menu (hamburger icon in the bottom left corner beside the home button). In the menu, Go to: Customization > Scripting > Script Deployment > Find existing script deployment > Parameters subtab > set parameters
If it’s for a new script click Deploy Script > it will redirect you to new script deployment
Example:
- Parameter ID = custscript_saved_search_id
- Deployment Value = customsearch_customer_followup
References
- SA: Script Parameter Preferences (ID: 10571)
- SA: SuiteCloud (ID: 1014757)
Notes
- Use script parameters for values that may change.
- Avoid hardcoding saved search IDs, employee IDs, or email recipients when admins may need to update them.
- Use clear parameter IDs and labels.
- Keep parameter values documented.
- Test parameter changes in sandbox before production.
- Confirm the script handles missing or blank parameter values.
- Do not store sensitive secrets in script parameters unless the design and access controls are properly reviewed.
Disclaimer
The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Oracle + NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
Share your insights and experiences in the NetSuite Admin Corner.