Dynamic script based sorting

I have a list layout which I want to dynamically sort, and I wonder if I can simplify this. There are many headings, but for simplicity assume we have

StudentFirstName
StudentLastName
Grade
Age

Some staff members prefer to sort by last name, some prefer to sort by first name.

The behavior I'd like is when someone clicks on "grade" it will sort by:

  • Grade Descending
  • EITHER StudentFirstName OR StudentLastName (based on staff member pref)
  • EITHER StudentFirstName OR StudentLastName (whichever one is that staff member's secondary)

Then when they click again on Grade I'd love to sort by:

  • Grade ASCENDING
  • And firstlast or lastfirst based on their preference

Is there some way to programmatically do this? What I want to do is write a script which basically says "execute the 'sort' script step, with these variables".

One other option would be to put everything in a portal and then I can dynamically sort the portal... but that would involve making a whole new collection of relationships, which feels cumbersome in a different direction, since all those relationships for the tables I want to view already exist in my default list view.

If you take each field in the list view, and copy them to the header area on top of the header label, pad them from the left say 200 characters, and create an OnObjectEnter trigger on each (you can add the trigger to all fields for all the fields selected. The process is SORT RECORDS BY FIELD with no field specificed, will sort on the field selected.

The global variables are in there to collect the information to display in the header area, which field is sorted in what order, for UX purposes.

Sort on Field Selected


Set Variable [ $PreviousSortField ; Value: $$SortField ] 
Set Variable [ $$SortField ; Value: Get (ActiveFieldName) ] 
If [ $PreviousSortField  = $$SortField ] 
	# 
Else
	Set Variable [ $$SortOrder ; Value: "Ascending" ] 
End If
# 
If [ $$SortOrder = "Ascending" ] 
	Sort Records by Field [ Ascending ] 
	Set Variable [ $$SortOrderLabel ; Value: "Ascending" ] 
	Set Variable [ $$SortOrder ; Value: "Descending" ] 
Else
	Sort Records by Field [ Descending ] 
	Set Variable [ $$SortOrderLabel ; Value: "Descending" ] 
	Set Variable [ $$SortOrder ; Value: "Ascending" ] 
End If
# 
Go to Record/Request/Page [ First ]
Scroll Window [ Home ]

I used to write SORT scripts for buttons used for list view header labels, but this is modular, so it can be used on any field in the list.

If you want to sort my > 1 field, you would need to script that sort, potentially placing it into a button as a "canned sort". Sort is one of those old school commands that does not allow passing in fields programmatically - hopefully someday in the product roadmap.

Thank you for this. Sorry for the super-slow reply. Got sucked into a conversion project that ate up a lot of time and just getting back to this. This is a SUPER helpful tip. Really appreciated.