6 Replies Latest reply on Feb 22, 2011 6:52 PM by PJSpark

    Sorting

    PJSpark

      Title

      Sorting

      Post

      I am finding the sorting to be somewhat limiting. I would like to create a dynamic way of sorting a layout the has several sub-summary parts. Unfortunately, FM's script step is hard coded; I can't use variables to specify an order. FM seems to do a pretty good job at allowing variables to specify step options, but sorting and also finding doesn't seem to be one of them.

      So then I tried Applescript, but no matter what I try in building a fields list, applescript and FM don't like it. The problem is trying to get the "field" specifier into the list with each field name. It sounds doable, but, alas, no luck.

      Has anybody been able to build a field list that the sort by statement likes?

      Thanks,

      Peter...

        • 1. Re: Sorting
          philmodjunk

          Without using applescript, you can have one script that sorts in different orders as specified by the user. The "hardwired" sort is a pain to deal with, but you can do it.

          If [YourTable::GlobalTextField = "Name" ]
             Sort [No dialog ; Restore ] //sort by the name field
          Else IF [YourTable::GlobalTextField = "Date"
             Sort [No dialog ; Restore ] //sort by the date field
          //and so on.

          This code can quickly get very long if you want to specify a lot of different sort orders or sort on multiple fields in combination.

          (Just think, there was a time when you could only have one sort order specified in any one script! That made things even more awful as you had to use Perform Script to call different one line scripts that each had a different sort order...)

          • 2. Re: Sorting
            PJSpark

            Thanks for the quick reply! I haven't been using FM for that long, so I don't know what it was like way back when, but I can imagine if we are on V11, it has come a long way. I hoping to avoid your scenario, because there are just too many combination. Unless, of course, if you can append to a previous sort request, that would go a long way.

            I used your method for perform find because you have exactly specify a field for the criteria. I was able to get around this by using Enter find mode and then setting a field by name, but I couldn't get it to work for "Omit"ting records. I had to use a bunch of If-Else.

            Thanks again

            Peter...

            • 3. Re: Sorting
              philmodjunk

              I used your method for perform find because you have exactly specify a field for the criteria. I was able to get around this by using Enter find mode and then setting a field by name, but I couldn't get it to work for "Omit"ting records. I had to use a bunch of If-Else.

              I don't see why you couldn't use setfieldbyName to set up an omit request just like you can for find request. Omit requests do need to be the last request when you set up multiple requests before performing the find.

              You can also enter find mode and then use constrain found set to filter some records from the current found set.

              • 4. Re: Sorting
                PJSpark

                I tried that method for omit but I couldn't get it to work. It always does a find.

                I Enter Find Mode with no options

                Set the fields and values with set by field name

                and perform the find with no options

                But the only way to specify Omit is to choose New in preform find and select omit without selecting a field, 'cause I don't want it to override my set by field name. But it always does the default find, so I gave up!

                Thanks

                Peter...

                • 5. Re: Sorting
                  Sorbsbuster

                  If you want to have a multi-criteria find with 2 Find Requests and 2 Omit requests you would:

                  Enter Find mode [Uncheck Pause ]

                  Set Field [FirstField ; MyFirstSearchCriterion ]

                  New Record/Request

                  Set Field [FirstField ; MySecondSearchCriterion ]

                  New Record/Request

                  Omit Record

                  Set Field [AnyOldField ; FirstCriterionToOmit ]

                  New Record/Request

                  Omit Record

                  Set Field [AnyOtherOldField ; AnotherCriterionToOmit ]

                  Perform Find

                  • 6. Re: Sorting
                    PJSpark

                    Sorbsbuster: Thanks for the post. I didn't realize that you use omit like that. I was always trying to use it through the preform find. It works nicely.

                    I used applescript to make a variable sort by using several if-then-else blocks to cover the possibilities. So for a maximum of six levels of sorting, I use six blocks for the number of possible fields used to sort at any one time.

                    Thanks for helping

                    Peter...