1 Reply Latest reply on Jan 13, 2011 10:11 AM by philmodjunk

    Toggle sort order

    InvectusIlumni

      Title

      Toggle sort order

      Post

      Hi guys --

      I've looked into this post here: Button to alternate from Sort Ascending to Sort Descending to write a script that toggles sort order for a given field, but I still need some advice.
      I have many list-view layouts and each has at least 10 fields that I'd like to sort. The solution discussed in 
      the post above would be great if I only had 1 or 2 layouts, but I don't think it's very efficient to create 7 different scripts that only differ from one another by one small element
      In the script below, I was wondering if there was a simpler way to specify the field to be sorted without rewriting the entire script for every single field.

      If [ PREFERENCES::text_sort="Ascending" ]
      Sort Records [ Specified Sort Order: TRANSACTIONS::transactionid; descending ]
      [ Restore ]
      Set Field [ PREFERENCES::text_sort; "Descending" ]
      Else If [ PREFERENCES::text_sort="Descending" ]
      Sort Records [ Specified Sort Order: TRANSACTIONS::transactionid; ascending ]
      [ Restore ]
      Set Field [ PREFERENCES::text_sort; "Ascending" ]
      Else
      Sort Records [ Specified Sort Order: TRANSACTIONS::transactionid; ascending ]
      [ Restore ]
      Set Field [ PREFERENCES::text_sort; "Ascending" ]
      End If
      

        • 1. Re: Toggle sort order
          philmodjunk

          Your example uses only one script that sorts the found set into 3 different sort orders. To specify more sort orders, you'd just add more Else IF, Sort [Restore] pairs of steps to your script.

          Note: you may want to use global variables instead of fields for keeping track of the current sort order--especially if you are using FileMaker 11.