Execute MapReduce Scripts from Other Scripts

by | Jan 17, 2022 | Tech Talk

Recently, we have had a couple of different projects where it was necessary to execute two or more MapReduce scripts consecutively and in sequence.  Since we do not know how long any of the scripts will run each time they are executed (some run much longer than others), we did not want to use scheduled deployments for each of the scripts individually. 

Having multiple scheduled deployments also would not guarantee that the subsequent scripts execute immediately after the previous script is completed or that the next one would not attempt to execute before the previous script was completed.  

To accomplish this in NetSuite tools, we used the scripted task scheduler methods available in NetSuite.

In the summarize function of each of the MapReduce scripts, we added the following code to trigger the execution of the next script in sequence.

Here is the standard code for creating a script task in NetSuite Suitescript 2.0:

var mrTask = task.create({
 taskType: task.TaskType.MAP_REDUCE,
 scriptId: 'mytaskid',
 deploymentId: 'custdeploy1',
 params: { parameter1: true,  parameter2: true }
var mrTaskId = mrTask.submit();

The following are the elements of the task.create method:

  • taskType – The type of script being executed.
  • scriptId – The internal ID (as a number) or script ID (as a string) for the script record.
  • deploymentId – The script ID (as a string) of the script deployment record.  This can be omitted if you only have a single deployment for the script.
  • params – optional parameters that are received and used by the executed script

Once we have executed the task.create() method, we use the task.submit() method to add our MapReduce script to the NetSuite scheduling queue for execution.

Since we are not scheduling the subsequent scripts and did not have multiple deployments for them, we did not require the use of the deployment id.  Omitting this from the code allows NetSuite tools to select any available deployment for the script to execute.  In our case, there was only one, so it was not necessary.

As a result, we simplified our script call to this:

var myTask = task.create({taskType: task.TaskType.MAP_REDUCE});
myTask.scriptId = ‘myScriptId’;
var myTaskId = myTask.submit();

About Us

We are a NetSuite Solutions Partner and reseller with 30+ years of combined experience.  We specialize in implementation, optimization, integration, rapid project recovery and rescue as well as custom development to meet any business need. If you would like more information on NetSuite or are in need of consultation for your project or implementation, feel free to contact NetSuite consultants.

To Contact Us Click Here.

Join our mailing list to stay up to date on the latest NetSuite solutions.