Solution to Sort Alphanumeric text values in search because sort.desc will give 9 greater

let searchResult = search.create({ type: search.Type.VENDOR_PAYMENT, filters: [ ['custbody_2663_reference_num', 'startswith', 'ACH_' + formattedToday] ], columns: [ search.createColumn({ name: 'custbody_2663_reference_num' }) ] }).run().getRange({ start: 0, end: 1000 });

let sortedResults = searchResult.sort((a, b) => { let aNum = parseInt(a.getValue('custbody_2663_reference_num').split('_').pop()); let bNum = parseInt(b.getValue('custbody_2663_reference_num').split('_').pop()); return bNum - aNum; // Sort in descending order }); // Get the top result after sorting let topResult = sortedResults.length > 0 ? sortedResults[0] : null; if (topResult) { let topReferenceNum = topResult.getValue('custbody_2663_reference_num'); // Do something with the topReferenceNum }

Leave a comment

Your email address will not be published. Required fields are marked *