[英]NetSuite: Using SUITESCRIPT 1.0 inside of SUITESCRIPT 2.0
[英]How to Reschedule the Schedule Script in Netsuite using SuiteScript 2.0 version
我想重新安排調度腳本,當調度腳本使用達到調控器限制之前。 Netsuite 中的調度腳本有 10,000 個單元。 在 SuiteScript 1.0 版本中,重新調度是通過“nlapiScheduleScript() api”實現的,但在 SuiteScript 2.0 版本中如何重新調度腳本。
幫助我實現這一目標,提前致謝。
N/task
和N/runtime
模塊有你要找的東西。 您將使用N/task
進行重新調度,並使用N/runtime
獲取當前腳本信息。
如果沒有您的確切代碼,我無法給出一個非常具體的示例,但是您的預定腳本最終看起來通常類似於:
/**
* @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
};
});
似乎 scheduleScriptTask.submit() 返回 null。
var taskId = rescheduleCurrentScript();
上面的 taskId 在記錄時返回 null。 它可能是 NetSuite 方面的錯誤嗎?
接受的答案有利於偶爾的收益。 除此之外,如果您知道自己會經常違反治理限制,您可能需要考慮使用Map/Reduce 腳本,因為它內置了 yielding/resuming。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.