ANS-0121 · SAVED SEARCHES & FORMULAS

How to Resolve ‘Unexpected Error’ in NetSuite Grouped Saved Searches?

Ensure grouped saved searches, especially those without parent record columns, include at least one sort column to prevent runtime errors.

Short answer

To prevent 'Unexpected Error' when running a grouped saved search in NetSuite, particularly when no columns are derived from the parent record, ensure that at least one column is configured for sorting. This applies to both UI-based searches and scripted searches, where explicit sorting is crucial for successful execution.

Scenario

Users may encounter an 'Unexpected Error' when attempting to execute a grouped saved search in NetSuite. This issue typically arises when the search definition includes grouped columns but lacks any explicit sorting criteria, especially if all grouped columns originate from joined records rather than the primary parent record.

Solution

When a grouped saved search is configured without any sorting columns, particularly when all grouped columns are derived from joined records rather than the primary parent record, an 'Unexpected Error' will occur. To resolve this, at least one column must be designated for sorting.For instance, a SuiteScript example demonstrating a grouped search without explicit sorting that would result in an error (using SuiteScript 1.0 functions for illustration):

var columns [];columns[0] new nlobjSearchColumn('internalid','customer','GROUP');columns[1] new nlobjSearchColumn('custitem_curriculum','item','GROUP');var result nlapiSearchRecord('invoice',null,filters,columns);

Adding a setSort() method to any column in the search definition would prevent this error. While the core principle of requiring a sort column for grouped searches remains valid, the specific API calls shown are from SuiteScript 1.0. NetSuite recommends using SuiteScript 2.x for new development, which employs different functions for search creation and sorting.In the NetSuite user interface, the system typically prompts or enforces the inclusion of at least one column from the parent record for sorting when creating grouped searches. However, when building searches programmatically, this enforcement may not be explicit, making it crucial to manually ensure a sort column is always included to avoid runtime errors.

Expert NetSuite Support

Need help with this NetSuite issue?

Saved Searches & Formulas consulting and configuration support

Talk to a consultant