I want to apply sorting on two columns using N/sea...
# ask-stanley-ai
t
I want to apply sorting on two columns using N/search module, while I can use sort key in coulmn, I don’t see anything for ordering, like I want to sort by item type first and then item, I am able to do this in Netsuite UI, but having a hard time replicating in suitescript.
c
AI generated answer (using internal Slack threads):
In SuiteScript, when you want to sort by multiple columns, the order of sorting is determined by the order in which you define your columns in your search. The first column defined with a sort will be sorted first, the second column with a sort will be sorted second, and so on. Here is an example of how you can define your search:
Copy code
javascript
var search = N.search.create({
    type: 'customrecord_my_custom_record',
    columns: [
        N.search.createColumn({
            name: 'custrecord_field1',
            sort: N.search.Sort.ASC
        }),
        N.search.createColumn({
            name: 'custrecord_field2',
            sort: N.search.Sort.ASC
        })
    ]
});
In this example, the search results will first be sorted by 'custrecord_field1' and then by 'custrecord_field2'. If you need more control over the sorting, you can also retrieve the search results into a JavaScript array and then use the array's sort function to sort the results in any way you want. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.8708269
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.868590713
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.862228811
Please provide your feedback on this answer.