最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Reschedule the Schedule Script in Netsuite using SuiteScript 2.0 version - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question asked Jul 21, 2016 at 4:41 Deepan MuruganDeepan Murugan 7713 gold badges22 silver badges42 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 14

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.

发布评论

评论列表(0)

  1. 暂无评论