Only When we are using the summary search, this option can be used.
Use case: Search for the Purchase history of the customer to get the last selling date, last selling price, and last selling Quantity.
Here we need to use the summary search where we have to fetch the maximum date and the maximum quantity on the maximum date.
In this case, we can use the When Ordered By option in the search.
Sample search code:
let transactionSearchObj = search.create({
type: 'transaction',
filters: [
["type", "anyof", "CustInvc", "CashSale"],
"AND",
["mainline", "is", "F"],
"AND",
['entity', 'anyof', customerId],
"AND",
["cogs", "is", "F"]
],
columns: [
search.createColumn({ name: 'internalid', join: 'item', summary: 'GROUP' }),
search.createColumn({ name: 'custitem_2srx_item_number', join: 'item', summary: 'GROUP' }),
search.createColumn({ name: 'salesdescription', join: 'item', summary: 'GROUP', sort: search.Sort.ASC }),
search.createColumn({ name: 'trandate', summary: 'MAX' }),
search.createColumn({ name: 'rate', summary: 'GROUP' }),
search.createColumn({ name: 'quantity', summary: 'MAX' }).setWhenOrderedBy({
name: 'trandate',
join: 'transaction'
})
]
})