I want to reschedule the schedule script , when the schedule script usage before hitting the governor limits. schedule script in Netsuite has 10,000 units. In SuiteScript 1.0 version, rescheduling is acheived by "nlapiScheduleScript() api " but in SuiteScript 2.0 version how to reschedule the script.
help me to achieve this,thanks in advance.
The N/task
and N/runtime
modules have what you're looking for. You'll use N/task
to do the rescheduling, and N/runtime
to get the current script info.
Without your exact code I can't give a very specific example, but your scheduled script will end up looking generally something like:
/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
*/
define(['N/task', 'N/runtime'], function(task, runtime) {
/**
* Reschedules the current script and returns the ID of the reschedule task
*/
function rescheduleCurrentScript() {
var scheduledScriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT
});
scheduledScriptTask.scriptId = runtime.getCurrentScript().id;
scheduledScriptTask.deploymentId = runtime.getCurrentScript().deploymentId;
return scheduledScriptTask.submit();
}
function execute(context) {
// Do stuff...
while(...) {
// Do processing in loop
// Check remaining usage and reschedule if necessary
if (runtime.getCurrentScript().getRemainingUsage() < 100) {
var taskId = rescheduleCurrentScript();
log.audit("Rescheduling status: " + task.checkStatus(taskId));
return;
}
}
}
return {
execute: execute
};
});
It seems like scheduledScriptTask.submit() is returning null.
var taskId = rescheduleCurrentScript();
taskId above returns null when logged. Is it possibly a bug in NetSuite side?
The accepted answer is good for occasional yields. In addition to this if you know you are going to often breach the governance limits you may want to consider a Map/Reduce script instead as it has yielding/resuming built in.
来源:https://stackoverflow.com/questions/38495014/how-to-reschedule-the-schedule-script-in-netsuite-using-suitescript-2-0-version