is there way to set the When Ordered By via search...
# suitescript
t
is there way to set the When Ordered By via search api
e
Example straight out of my free cookbooks
1000 1
t
am I doing something wrong? it is returning a wrong result in script then when I run a saved search in the ui search.create({ type: 'file', filters: [ { name: 'internalid', operator: 'anyof', values: fileArr.map(el => el.id) }, { name: 'field', join: 'systemnotes', operator: 'anyof', values: 'MEDIAITEM.SFILECONTENTHASH' } ], columns: [ search.createColumn({ name: 'internalid', summary: 'GROUP', label: 'Internal ID' }), search.createColumn({ name: 'date', join: 'systemNotes', summary: 'MAX', label: 'Date', sort: search.Sort.DESC }), search.createColumn({ name: 'newvalue', join: 'systemNotes', summary: 'MAX', label: 'Content Hash' }).setWhenOrderedBy({ name: 'date', join: 'systemNotes' }) ] }) .run().each(function(result) { let fileJson = fileArr.find(el => el.id === result.getValue({ name: 'internalid', summary: 'GROUP' })); if (!fileJson) return true; fileJson.contenthash = result.getValue({ name: 'newvalue', join: 'systemNotes', summary: 'MAX' }); return true; });
m
.setWhenOrderedBy
can be buggy in SuiteScript. I've had success using a formula instead, e.g:
MAX({systemNotes.newvalue}) KEEP (DENSE_RANK LAST ORDER BY {systemNotes.date})