2 Replies Latest reply on Aug 26, 2015 2:00 PM by raybaudi

    Dynamic button to Sort dates ascending

    MarkRiddle

      Title

      Dynamic button to Sort dates ascending & descending

      Post

      I'm trying to create a single button that will sort dates in a my "date" field in ascending order when clicked.  Then, if clicked again it will resort in descending order.  It seems pretty straight forward but I'm having such difficulty with it.  Is that even possible?

        • 1. Re: Dynamic button to Sort dates ascending & descending
          philmodjunk

          It's quite possible, but you need to use a global variable or global field to keep track of the current sort order.

          If [$$Sort = "Ascending" ]
             Sort Records [no dialog ; Restore ]
             Set Variable [$$Sort ; value: "Descending" ]
          Else
              Sort Records [No dialog ; Restore ]
              Set Variable [$$Sort ; value: "Ascending" ]
          End If

          • 2. Re: Dynamic button to Sort dates ascending
            raybaudi

            .. or, without a field or a variable ( and with the new sort by field script step ):

             

             

            If [( GetNthRecord ( YourTable::YourDatetField ; 1 ) > GetNthRecord ( YourTable::YourDatetField ; Get ( FoundCount ) ) ]
            Sort Records by Field [ Ascending ; YourTable::YourDateField ]
            Else
            Sort Records by Field [ Descending ; YourTable::YourDateField ]
            End If