ANS-0506 · SUITESCRIPT DEVELOPMENT

How to Resolve nlapiYieldScript Errors in NetSuite Scheduled Scripts

Understand why the SuiteScript 1.0 nlapiYieldScript function may return an unexpected error when processing search results, and learn the correct approach.

Short answer

The nlapiYieldScript function in SuiteScript 1.0 does not support nlobjSearchResultSet objects. To resolve the 'must be called from a scheduled script' error, ensure your script uses nlapiSearchRecord and processes results with a standard FOR loop instead of nlapiCreateSearch().runSearch() when yielding is required.

Scenario

When developing a SuiteScript 1.0 scheduled script that processes a large volume of data, developers may encounter an error stating 'nlapiYieldScript must be called from a scheduled script,' even when the function is correctly invoked within a scheduled script. This misleading error typically arises when attempting to use nlapiYieldScript with unsupported object types.

Solution

The error 'nlapiYieldScript must be called from a scheduled script' in SuiteScript 1.0 is often misleading. The actual cause is typically the use of an unsupported object type with the nlapiYieldScript function.

For SuiteScript 1.0, nlapiYieldScript supports the following object types:

nlobjConfiguration, nlobjContext, nlobjFile, nlobjRecord, nlobjSubrecord, nlobjSearchColumn, nlobjSearchFilter, nlobjSearchResult, and all 3rd party XML Library objects. All other object types are not supported.

Specifically, nlapiYieldScript in SuiteScript 1.0 does not support nlobjSearchResultSet objects, which are returned by nlapiCreateSearch().runSearch().

To resolve this issue in SuiteScript 1.0, developers should modify their script to use nlapiSearchRecord instead of nlapiCreateSearch().runSearch(). The nlapiSearchRecord function returns an array of nlobjSearchResult objects, which are compatible with nlapiYieldScript. The results should then be iterated using a standard FOR loop.

Important Note on SuiteScript Versions:

The nlapiYieldScript function is part of SuiteScript 1.0. In modern NetSuite development, SuiteScript 2.x is the recommended platform. SuiteScript 2.x does not have a direct equivalent for nlapiYieldScript or nlapiSetRecoveryPoint. For long-running scripts in SuiteScript 2.x, yielding functionality is typically managed by:

  1. Utilizing the Map/Reduce script type, which automatically incorporates yielding.

  2. Manually managing script state and rescheduling using the N/task module for other script types.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant