nlapiScheduleScript()与nlapiYieldScript()的区别及治理点重置选择场景
nlapiScheduleScript() vs nlapiYieldScript() in NetSuite: Key Differences & Governance Reset Use Case
Core Differences
- Purpose & Execution Flow
nlapiScheduleScript(): This function is all about deferring work to later. When you call it, you're queuing up a separate instance of a script to run asynchronously in the background. Your current script keeps executing immediately after the call—no pause, no waiting. It’s like handing a side task to a teammate to handle later while you stay focused on your current work.nlapiYieldScript(): This pauses the current running script temporarily. It gives NetSuite’s system a chance to free up resources, and when the script resumes, it gets a full, fresh set of governance points. Think of it as taking a quick mid-task break, then coming back with a full "energy bar" to keep pushing forward.
- Governance Handling
nlapiScheduleScript(): Doesn’t reset the current script’s governance. The queued script gets its own separate governance pool, but your original script’s remaining points stay exactly as they were before the call.nlapiYieldScript(): This is the one that directly resets the current script’s governance to the full allocation for its type (e.g., 10,000 points for scheduled scripts). That’s its primary superpower for long-running jobs.
- Use Case Focus
nlapiScheduleScript(): Great for splitting large, independent tasks into chunks that can run at different times (like processing batches of records overnight), or offloading non-urgent work so your current script can finish quickly without tying up resources.nlapiYieldScript(): Perfect for continuous, long-running scripts that process a stream of records (like looping through 10,000+ transactions) where splitting into separate scheduled jobs would be cumbersome. It lets you keep the same script instance alive while refreshing governance mid-execution.
Which One Resets Governance?
nlapiYieldScript() is the function built specifically to reset governance points for the current running script.
Ideal Scenarios for nlapiYieldScript():
- You’re running a loop that processes hundreds or thousands of records, with each iteration consuming governance points (e.g., searching, updating records). After every N iterations (say, 100 records), call
nlapiYieldScript()to refresh your governance pool and avoid hitting limits mid-job. - Your script needs to maintain state between batches (like tracking which records you’ve already processed) that would be hard to pass to a separate scheduled script instance. Since
nlapiYieldScript()resumes the same script, you can keep variables in memory instead of storing state in a custom record or file.
When to Use nlapiScheduleScript() Instead:
- The task can be split into fully independent batches with no shared state required. For example, processing orders from different regions—each region’s batch can run as a separate scheduled script without needing to coordinate with the others.
- You want to run the task during off-peak hours to avoid impacting user-facing system performance. Scheduled scripts let you set a specific execution time for this.
内容的提问来源于stack exchange,提问作者Netsuite Technical
相关产品推荐
相关产品推荐

