How to Task a Map Reduce Script

in , , May 2nd, 2024
Note: This article is a best-practice blog post related to SuiteScript, and so is directed at developers. If you are working to troubleshoot an issue and do not have experience coding in SuiteScript, specifically as it relates to SuiteCommerce or SCA, we reccomend reaching out to a SuiteCommerce developer who can support you!
man smiling while sitting and using MacBook

Why Task a Map Reduce Script?

As a developer, you may encounter a situation where you need to trigger a complicated process from something like a User Event Script (record save or creation).

However, user Event Scripts have limited script governance, while Map Reduce scripts have much, much more. Thus, tasking a Map Reduce Script to process data for you is often a better solution.

Below is the code you can use to trigger a Map Reduce script using the task module, as well as a few tips to ensure the solution's success.

Code: Using the Task Module to Trigger a Map Reduce Script

//Be sure to load the "task" module!
//create the task
let mapReduceTask = task.create({
    taskType: task.TaskType.MAP_REDUCE,
    scriptId: "customscript_ag_mr_script_id",
    deploymentId: "customdeploy_ag_mr_deployment_id",
    params: {
        custscript_param_1: JSON.stringify(someObject),
        custscript_param_2: someString
    },
});
//submit the task
mapReduceTask.submit();
  • Ensure the scriptId and deploymentId match the existing Map Reduce script you want to run.
  • Pass data to the Map Reduce script by defining script parameters on the Map Reduce Script record and setting them in the code (shown above).
NOTE: Remember that the task module can be used to trigger many other processes, not just Map Reduce scripts.

Author: Sam Gagliardi


Got stuck on a step in this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart