Is it possible to load a saved search in script and change the column that it is sorted by?

I use a saved search for a Suitelet and want to get around the limitation that the native column sort ONLY sorts the data on the current page. Instead, my client wants the entire dataset re-sorted.

I can get the columns off the search object after I load the search, and I try to overwrite the search.columns[i].sort element with “DESC” and set the default column to “NONE” but the results are not showing the data sorted.

Unfortunately, I think I need to create a NEW scripted search… which is a pain in the behind but not the worst. Anyone ever figure out how to change the sort direction of an existing saved search in script??

Scripting in 2.0 ~~~ any/all help helps!


var searchA = search.load({ id : 1430});

var columns = searchA .columns;

columns[1].sort = "NONE";

columns[8].sort = "DESC";

Beginner Asked on October 1, 2019 in SuiteScript.

The sort property might be read-only. It’s not actually documented as a property on the Column object, and with some quick testing in the console I was unable to change the sort order. I was essentially trying the same approach as you, using the search.Sort enum values instead.

on October 1, 2019.
Add Comment
2 Answer(s)

https://system.na0.netsuite.com/app/help/helpcenter.nl?fid=section_456142211913.html

After you create a column, you cannot change the sort order of the column. If you use the same column in another search and specify a new sort order, the previous sort order is still used.

Make a new columnn to replace the one you want to change

Advanced Answered on October 1, 2019.
Add Comment

Thanks for the quick responses! Yes so my approach is:

  1. Field on SL for the column you want to sort by, another field for Descending (checkbox)
  2. Load the saved Search in script, if there is a column to sort by:
  3. Get columns of existing saved search
  4. Create a NEW scripted search, same type, maybe add a filter to remove “blank” values – I have noticed the sort descending assumes blanks are first?
  5. Iterate through columns, create NEW search columns and push onto an array
    • If the column is the column to sort by, set the sort attribute for that search column
  6. Run the search

So going to test how this affects pagination… I noticed when I changed the saved search sort on the actual saved search definition, the “pageNumbers” changed to the sorted appreviation (A-H) changes to (0-12) when sorting on name vs. quantity.

 

Hope this helps someone else dealing with the same issue!

Beginner Answered on October 2, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor