ANS-0605 · SUITESCRIPT DEVELOPMENT
How to Pass and Retrieve Parameters in NetSuite Scheduled Scripts (SuiteScript 2.x)
Learn the best practices for sending and accessing custom parameters within SuiteScript 2.x scheduled scripts to enhance script flexibility.
Short answer
To pass parameters to a SuiteScript 2.x scheduled script, use the N/task module's params object when scheduling. Retrieve these parameters within the script using the N/runtime module's getParameter method, specifying the custom script parameter's name.
Scenario
NetSuite users often need to pass dynamic data or configuration settings to scheduled scripts to control their behavior or process specific records. Without a clear understanding of the correct parameter passing and retrieval mechanisms, scripts may not execute as intended or may require hardcoding values, reducing their reusability and flexibility.
Solution
When working with SuiteScript 2.x scheduled scripts, ensure parameters are passed and retrieved using the recommended N/task and N/runtime modules. This approach ensures proper data transmission and access within the NetSuite environment.
To pass parameters when scheduling a script, utilize the N/task module and include a params object within the task.create method:n
javascriptnvar task = require('N/task');nvar scheduledScriptTask = task.create({n taskType: task.TaskType.SCHEDULED_SCRIPT,n scriptId: 'customscript_your_scheduled_script_id',n deploymentId: 'customdeploy_your_deployment_id',n params: {n 'custscript_paramname_one': 'paramValueOne',n 'custscript_paramname_two': 123n }n});nvar taskId = scheduledScriptTask.submit();nTo retrieve these parameters within the scheduled script itself, use the N/runtime module's getCurrentScript().getParameter method:n
javascriptnvar runtime = require('N/runtime');nvar paramValueOne = runtime.getCurrentScript().getParameter({ name: 'custscript_paramname_one' });nvar paramValueTwo = runtime.getCurrentScript().getParameter({ name: 'custscript_paramname_two' });n// Use paramValueOne and paramValueTwo in your script logicnThis method ensures that parameters are correctly transmitted and accessible, providing robust and flexible scheduled script functionality.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
