Script parameters are useful when there is a requirement to store data specific to a script but more accessible to all users other than developers. Using script parameters
we can avoid hardcoding certain values to the code that is required to be modified often. Also these values can be modified by anyone having access to the parameters without even knowing
anything about the code. Also script parameters can store a wide range of inputs that can be used as required.
But we cannot set values in script parameter using suitescripts and use that value after the execution of the script deployment.
However we can pass values to script parameter in map/reduce and scheduled scripts. This value will be available for the runtime of the script deployment via script.
We cannot see this value through NetSuite UI even the map/reduce or scheduled script deployment is running.
One of the best use case of this scenario is to store the last updated internal id of a record in a scheduled script in case we are rescheduling the task. Since the script
parameter will be available during the execution time of the scheduled script, we can store the last updated record’s internal id and start from the next internal id if we are rescheduling the task due to governance issues.
How to pass values values to script parameters from a map/reduce or scheduled script
The only time you can pass a value to a script parameter outside of the UI is when you call the function “task.create()” to schedule a script.
Refer the following code of triggering a map/reduce deployment. The code for scheduled processes is also similar.
// Add additional code
...
var mrTask = task.create({
taskType: task.TaskType.MAP_REDUCE,
scriptId: 34,
deploymentId: 'custdeploy1',
params: {
custscript_newparameter : value//Here internal id of script parameter is "custscript_newparameter"
}
});
...
// Add additional code
Values set in script parameters can be accessed by using Script.getParameter(options) method in the module N/runtime Module. Refer the code below:
// Obtain an object that represents the current script
var newScript = runtime.getCurrentScript();
// Obtain the value of the script parameter
var scriptParameterValue = newScript.getParameter({name: 'custscript_mycheckbox'});