4 Replies Latest reply on Jun 9, 2016 8:28 AM by PieroF

    Found set and sort order lost when file is closed

    PieroF

      This is a reviewed/simplified version of my older post https://community.filemaker.com/thread/103206

      But the issue I describe is the same and is still there.

       

      The problem:

      Whenever (almost always...) I close the last window of a file its found set and its sort order are lost.

      That is, when I open again that file its window shows an older found set and an older sort order, both older than those visible at closing time.

      I think this very inconvenient since I'd expect to find the same window that I left before closing, including found set and sort order.

       

      How to reproduce the problem:

      You can easily reproduce this issue:

      1. create a very simple and small test file with 3-4 records of only a couple fields

      2. make some changes on the found set (e.g. omit some records) and/or the sort order - remember the situation before closing

      3. close the file

      4. open the file again - and compare what you see with what you left before closing: they are usually different

       

      Originally I thought this had to do with the affected file being related to some other file (see my description in the old post above, actually a bit too complicated...) and at that time it seemed that closing all related files would instead preserve found set and sort order. But making additional tests I found out that this is not always true, and this behavior is 90% likely to occur independent from any existing relationship.

       

      Is there a workaround ?

      Note: I tried to use script steps Save Record/Request and Window Update with data flashing. If it had worked I could have used them in a OnWindow Close or OnLastWindow Close triggers. But those script steps don't do the job; it seems they commit only data values, not their presentation in the window.

       

      Thanks

      Piero

        • 1. Re: Found set and sort order lost when file is closed
          mikebeargie

          Filemaker has never advertised saving a "state" of a found set or sort order after a user's session when the file is terminated as far as I know.

           

          You can use the filemaker's recent/saved finds menu to save and recall found sets on a per-user basis, or you can script the intended found set as part of your OnFirstWindowOpen script trigger.

           

          As a third alternative, you can use a snapshot link to restore a specific found set, sort order, mode and position, essentially a "state" for where you left off. Snapshot links can be generated by a script, so you could potentially tie it to the last window close trigger script so that it saves the state automatically somewhere. However it would be the user's responsibility to re-launch using the last snapshot that was generated.

          • 2. Re: Found set and sort order lost when file is closed
            PieroF

            Thanks for your answer.

             

            As far as I understand recent/saved finds commands area available only on menu, not in scripts.

            I'd like to make the whole "workaround" hidden by some script.

             

            To script the intended found set as part of a OnFirstWindowOpen script trigger I should be able to save it first before exiting. Is the ListOf summary the only way ? and there is a way to save also the current Sort order ?

             

            I understand the Snapshot link use, but as you say the user must then open that snapshot not the usual file.

             

            So now my question is whether I may write scripts that save and reuse found set and sort order information...

             

            Thanks

             

            Piero

            • 3. Re: Found set and sort order lost when file is closed
              mikebeargie

              Yes, the List summary would work well for that. However that will only get you the found set ID list (which you would then have to parse in a giant find when returning to the system).

               

              This doesn't include sort order, and I do not know if there is a way to retrieve the current sort order at all natively. Get(SortState) will only return if the records in the current window are sorted or not. If all of your sorting is tied to scripts then you could store the sort order in

               

              This is where snapshot links are better, since they save the "state" as much as possible in a single easy file.

               

              You could potentially save the .fmpsl snapshot link to a container field tied to the user, and just overwrite it each time they exit it. I'm not entirely sure how you would launch it when they reopen the file, but it could be as simple as exporting the snapshot to a temp path and then opening it via URL and closing the original file.

               

              EG:

               

              OnLastWindowExit Script:

               

              Set Variable [ $file ; "file:" & get(temporarypath) & "shortcut.fmpsl" ]

              Save Records As Snapshot Link

              Go To Layout

              Perform Find

              If

                 New Record

                 Set Field

              End If

              Insert File

              Exit Script

               

               

              OnFirstWindowOpen Script:

               

              Go To Layout

              Perform Find

              If

                 Exit Script

              Else

                 Set Variable [ $file ; "file:" & get(temporarypath) & "shortcut.fmpsl" ]

                 Export Field Contents

                 Delete Record

                 Open URL

                 Close File

              End If

               

              Note you will need to delete the record after exporting it so it doesn't cause an infinite loop of attempting to open the fmpsl over and over.

               

              Maybe play around with that to see if it gets you what you need.

              • 4. Re: Found set and sort order lost when file is closed
                PieroF

                Thanks Mike for you detailed answer!

                 

                Since there is no built-in way, your scripts appears to be the best solution.

                As soon as I have a slot of time I'll try to implement it and let you know!

                Piero