2

I am using Suitescript 2.0. There I am trying to reschedule a script for a particular type of error.

I got the below code which can be used to rescheduled the script immediately.

var scriptTask = task.create({
     taskType: task.TaskType.MAP_REDUCE
});
scriptTask.scriptId = 'customscript_id';
scriptTask.deploymentId = 'customdeploy_id';
var scriptTaskId = scriptTask.submit();

But I am mainly looking for some option to run it after a certain time like after an hour.

Is it possible to achieve by passing any kind of parameter to the above task?

Any other alternative approach would also helpful.

Monaj
  • 245
  • 3
  • 15
  • 1
    One option is to create and submit a scheduled script task that then creates and submits a Map/Reduce script task. – Brian Jan 11 '21 at 21:50
  • Thanks Brian, I was also thinking about the same approach, if no other options available – Monaj Jan 11 '21 at 22:04

1 Answers1

2

I had a similar issue, I needed to delay my schedule a certain time in your case a map/reduce script which should be the same.

I fixed it with this approach.

Here is sample code with the approach.

/**
  • @NApiVersion 2.x
  • @NScriptType ScheduledScript
  • @NModuleScope SameAccount */ define(['N/file', 'N/record', 'N/render', 'N/runtime', 'N/search', 'N/ui/serverWidget', 'N/format', 'N/task', 'N/log'],

function(file, record, render, runtime, search, serverWidget, format, task, log) {

/**
 * Definition of the Scheduled script trigger point.
 *
 * @param {Object} scriptContext
 * @param {string} scriptContext.type - The context in which the script is executed. It is one of the values from the scriptContext.InvocationType enum.
 * @Since 2015.2
 */
function execute(scriptContext) {
     wait(20000); // it waits 20 sec       
   //whatever you want to do
}
function wait(ms){
   var start = new Date().getTime();
   var end = start;
   while(end < start + ms) {
     end = new Date().getTime();
  }
}



return {
    execute: execute
};

});

  • Thanks Mattour, I tried this but for me I am getting governance limit issue. So could not use this. – Monaj May 24 '21 at 17:57