Challenges often arise when saved searches return line-level elements. Using methods like run() or getRange() can complicate data aggregation because result.id corresponds to line numbers, which may cause unintended behaviors, especially when dealing with multi-line transactions.
Consider this use case:
define(['N/search'], function(search) {
function getInputData() {
return search.create({
type: search.Type.SALES_ORDER,
filters: [['status', search.Operator.ANYOF, 'SalesOrd:F']],
columns: ['internalid', 'item', 'quantity']
});
}
return { getInputData };
});
Since the search object itself is returned, handling results in map or reduce allows you to mitigate issues like unreliable result.id by focusing on the parent-level records. This eliminates conflicts caused by line-level data and ensures accurate processing
You can add the record internal id as a column to avoid this issue. This value can be used instead of result.id