It is not necessary to close all the Item lines for an order to have closed status. There are two possible options.
Options-1
All the item lines in the orders are closed.
Option-2
Some of the Item lines in the order are closed and the remaining item lines are fulfilled or received.
So if we would like to get the closed order, which has all the lines closed. The below search can be used for such purposes.
let orderSearchObj = search.create({
type: "transaction",
filters:
[
["type", "anyof", "SalesOrd", "PurchOrd"],
"AND",
["status", "anyof", "SalesOrd:H", "PurchOrd:H"],
"AND",
["taxline", "is", "F"],
"AND",
["cogs", "is", "F"],
"AND",
["shipping", "is", "F"],
"AND",
["max(quantityshiprecv)", "equalto", "0"]
],
columns:
[
search.createColumn({ name: "internalid", summary: "GROUP", sort: search.Sort.ASC, label: "Internal ID" }),
search.createColumn({ name: "type", summary: "GROUP", label: "Type" }),
search.createColumn({ name: "quantityshiprecv", summary: "MAX", label: "Quantity Fulfilled/Received" })
]
});