6 Replies Latest reply on Jun 8, 2017 3:17 AM by thomasseidler

    AppleScript issue with "sort"

    seevogel

      Summary

      AppleScript issue with "sort"

      Product

      FileMaker Pro

      Version

      11, 12 and maybe others

      Operating system version

      OSX 10.9.1

      Description of the issue

      tell application "FileMaker Pro 11 Advanced"
           sort layout "myLayout" by field "name" of table "myTable" of database "myDatabase" in order ascending
      end tell


      TURNING INTO:

      tell application "FileMaker Pro 11 Advanced"
           sort layout "myLayout" by field "name" of table "myTable" of database "myDatabase" in order stop
      end tell

      Steps to reproduce the problem

      create a new database with the given Names and enter some records.

      Open the AppleScript-Editor and enter following code:

      tell application "FileMaker Pro 11 Advanced"
           sort layout "myLayout" by field "name" of table "myTable" of database "myDatabase" in order ascending
      end tell

      Actual result

      the script running without recognizable problems BUT:

      If you look below to the bottom of the AppleScript-Editor "Events"

      "ascending" turned into "stop".
      "descending" turning into "note"

        • 1. Re: AppleScript issue with "sort"
          TSGal

               seevogel:

               Thank you for your post.

               This issue has been prevalent since FileMaker Pro 2.  In addition to "ascending" and "descending", "update" is substituted for "custom".

               TSGal
               FileMaker, Inc.

          • 2. Re: AppleScript issue with "sort"
            thomasseidler

            Hi TSGal, I know this is old, but how on earth do you use "custom" sorting in Applescript? I'd love to define which value list to use, but not sure how? What argument is it expecting? It just selects the same value list each time, an entirely arbitrary random choice seemingly, but perhaps  my first one... Also, can I turn off, "keep records in sorted order"? Sort by calculated fields etc would be preferable of course, but in the meanwhile we must make do!

             

            Thanks again, Tom

            • 3. Re: AppleScript issue with "sort"
              seevogel

              tell application "FileMaker Pro Advanced"

                tell database "NameOfDatabase"

                sort layout "NameOfLayout" by {field "NameOfField" of table "NameOfTable"} in order custom

                end tell

              end tell

              • 4. Re: AppleScript issue with "sort"
                seevogel

                Here as custom function for "perform AppleScript" ScriptStep

                 

                 

                /*

                AS_dynamic_Sort ( List_of_FieldNames ; AscDescCustom )

                 

                version 11

                ---------------------------------------------

                Thomas Siebert, 07.06.2017

                thomas@t-seabird.de

                www.t-seabird.de

                ---------------------------------------------

                 

                 

                Sort records dynamically by a list of fieldnames and order.

                 

                 

                AscDescCustom: asc, desc, ascending, descending, custom

                 

                 

                Use the ScriptStep "Perform AppleScript" using the option "Calculated AppleScript"

                You also shall use "Perform AppleScript" directly from a button.

                 

                 

                */

                 

                 

                Let ([

                myTable = Quote ( Get ( LayoutTableName ) ) ;

                myFields = "field \"" & Substitute ( List_of_FieldNames ; [ ¶ ; "\" of table " & myTable & ", field \"" ] ) & "\" of table " & myTable

                ];

                 

                 

                "set SortOrder to " & Substitute ( Lower ( AscDescCustom ) ; [ "asc" ; "ascending" ] ; [ "desc" ; "descending" ] )  & "

                ¶tell database " & Quote ( Get ( FileName ) ) & "

                ¶ sort layout " & Quote ( Get ( LayoutName ) ) & " by { " & myFields & " } in order SortOrder

                ¶end tell"

                 

                 

                 

                )

                • 6. Re: AppleScript issue with "sort"
                  thomasseidler

                  Yes, I certainly understand and am using similar applescript, but there is no way to specify *which* value list it uses to sort by. It defaults to a given one (and also insists on "keep records sorted in order"). However, I've gotten around this by turning that single Value List into a VirtualValueList, which gives me the flexibility I need to define custom sorts on the fly... It would, of course, be oh so much nicer to have a Sort By Calculation, where we pass it JSON of filename and ascending, descending etc