Call MapReduce from another server side script in netsuite

Map/reduce scripts can be submitted for processing on an on-demand basis from another server-side script. You can submit a deployment this way by using the task.ScheduledScriptTask API. For the call to be successful, the Status field on the script deployment record must be set to Not Scheduled.

Feel free to reach out Netsuite Solution provider  TheSmilingCoders for proper netsuite implementationnetsuite consultation , netsuite customizationnetsuite Supportnetsuite Training 

You can also submit an on-demand deployment from the UI. For details, see Submitting an On-Demand Map/Reduce Script Deployment from the UI.

Note that after you submit an on-demand deployment of a script, the script does not necessarily execute right away. After a script is submitted for processing, there may be a short system delay before the script is executed, even if no scripts are before it. If there are scripts already waiting to be executed, the script may wait to be executed until other scripts have completed.

The properties of a map/reduce script deployment. You can use this object to programmatically submit a script deployment for processing.

To use the MapReduceScriptTask object: In the NetSuite UI, create the script record and script deployment records.

Use task.create(options) to create the MapReduceScriptTask object.

Use the MapReduceScriptTask object properties to set the script and deployment properties.

Use MapReduceScriptTask.submit() to submit the deployment for processing.

Use the properties for the task.MapReduceScriptTaskStatus object to get the status of the map/reduce script.

To submit an on-demand map/reduce script instance from a script:

Step 1)  Create your map/reduce script entry point script. This process includes uploading a JavaScript file and creating a script record based on that file.

Step 2) In the server-side script where you want to submit the map/reduce script, call task.create(options) to return a task.MapReduceScriptTask object.

var scriptTask = task.create({taskType: task.TaskType.MAP_REDUCE});

Set the MapReduceScriptTask.scriptId and MapReduceScriptTask.deploymentId properties:

scriptTask.scriptId = ‘customscript1’;

scriptTask.deploymentId = ‘customdeploy1’;

The system does not require you to set a value for the deploymentId property. If you omit this value, the system searches for and uses any available deployment record for the script record you identified with the scriptId property. For a deployment to be considered available, three conditions must be met: The deployment record must have a status of Not Scheduled, its Deployed option must be set to true, and no unfinished instances of the deployment can exist.

Call MapReduceScriptTask.submit() to submit the script for processing.

scriptTask.submit();

/*Code snippet for the description above*/

/**

 *

 * @NApiVersion 2.x

 * @NScriptType ScheduledScript

 *

 */

Define([‘N/search’, ‘N/task’,],function(search,task){

              Function callMRfromScript(){

              /*

              * Initial logic of the script

              */

//utilize task module for calling mapreduce

var mapReduceScriptId = ‘customscript_test_mapreduce_script’;

               log.audit(‘mapreduce id: ‘, mapReduceScriptId);

              var mrTask = task.create({

                taskType: task.TaskType.MAP_REDUCE,

                scriptId: mapReduceScriptId,

                deploymentId: ‘customdeploy_test_mapreduce_script’

                 var mrTaskId = mrTask.submit();

}

return{

execute: callMRfromScript

};

)};

Feel free to reach out Netsuite Solution provider  TheSmilingCoders for proper netsuite implementationnetsuite consultation , netsuite customizationnetsuite Supportnetsuite Training 

contact us : info@smilingcoders.com

Facebook : https://www.facebook.com/Smiling-Coders-Netsuite-Training-Implementation-and-Support-1591053827660082/

Linkedin : https://www.linkedin.com/company/netsuite-academy/


4 Comments

ปั้มไลค์

May 26, 2020 at 10:19 pm

Like!! I blog quite often and I genuinely thank you for your information. The article has truly peaked my interest.

    Smiling Coders

    August 1, 2020 at 11:17 pm

    Thanks for your kind words.

Kieran

August 1, 2020 at 11:32 am

Thanks for a marvelous posting! I certainly enjoyed reading it, you happen to be a great author.I will be
sure to bookmark your blog and will eventually come back from now
on. I want to encourage you continue your great writing, have a nice weekend!

my homepage; Royal CBD

    Smiling Coders

    August 1, 2020 at 11:13 pm

    Thanks for your comments

Leave a Reply