To resolve the Unexpected Error when using setWhenOrderedBy method on internalid Search Column of a custom Record create the Saved Search in the UI. This Saved Search can be later accessed through SuiteScript.
- Create Saved Search (documented in SuiteAnswers article Defining a Saved Search)
- Execute the Saved Search via SuiteScript (example is available in SuiteAnswers article Executing Existing Saved Searches)
Additional Alternate Solution: Copy the saved search through script, then run the copied script through UI.
Note: This is an alternate solution to Defect #268447: SuiteScript > Server Side Script with search on custom record throws UNEXPECTED ERROR when setWhenOrderedBy method is used on the internalid nlobjSearchColumn