To customize the behavior of a NetSuite script for different records, use the getParameter() function. This function returns the value of a script parameter for the currently executing script, allowing you to pass different parameters to the same script. Here’s how to use it in SuiteScript 2.0 and set the parameter value at deployment.
define([‘N/runtime’, ‘N/log’], function(runtime, log) {
function executeScript(context) {
// Retrieve the script parameter
var paramValue = runtime.getCurrentScript().getParameter({
name: ‘custscript_my_parameter’
});
// Log the parameter value for debugging
log.debug(‘Script Parameter’, paramValue);
// Use the parameter value to customize the script’s behavior
if (paramValue === ‘value1’) {
// Logic for handling value1
log.debug(‘Handling’, ‘Logic for value1’);
} else if (paramValue === ‘value2’) {
// Logic for handling value2
log.debug(‘Handling’, ‘Logic for value2’);
} else {
// Default logic
log.debug(‘Handling’, ‘Default logic’);
}
}
return {
execute: executeScript
};
});
Setting the Parameter Value at Deployment
Navigate to Script Deployment:
- Go to Customization > Scripting > Script Deployments.
- Edit or Create a Deployment:
- Edit an existing deployment or create a new one for your script.
- Set the Parameter Value:
- In the Parameters section, find the custom parameter (e.g., custscript_my_parameter).
- Enter the desired value for the parameter (e.g., value1 or value2).
- Save the Deployment: Save your changes to apply the parameter value to the script deployment.
Script: 
Deployment: 
By using getParameter() and setting parameter values at deployment, you can make a single NetSuite script versatile enough to handle different records and scenarios based on the provided parameters. This approach allows for greater flexibility and reusability of your scripts in NetSuite.