6 Replies Latest reply on Jul 2, 2015 8:33 AM by philmodjunk

    Simple find script doesn't work

    CharlesMaurer

      Title

      Simple find script doesn't work

      Post

      From what I can see, this script ought to find all appointments on a date selected.  The first execution does this but subsequent executions continue to search for the original date even if a different date is specified.  Can somebody please explain to me my mistake? FMPro14

      Go to Layout [ "chooseDate" )
      Enter Find Mode [ Pause ]
      Sort Records [ Restore ; No dialog ]
      Go to Layout [ "listAppointments" ]
      Enter Browse Mode []

        • 1. Re: Simple find script doesn't work
          philmodjunk

          Your script enters find mode, but doesn't specify any find criteria nor does it perform the find.

          Scripted Finds would be set up in one of the following ways:

          Perform Find [Restore]

          or

          Enter Find Mode [pause]
          Perform Find[]

          or

          Enter Find mode []--pause check box has been cleared
          Set Field [yourTable::field ; <expression goes here>]
          Perform Find []

          My preference is to use this last option whenever possible.

          In the last option <expression goes here> can be replaced by a calculation such as Get ( CurrentDate ) and can include a reference to data entered previously into a global field. Thus, you could enter/select a date in a global date field and then use Set field to set up the find request.

          • 2. Re: Simple find script doesn't work
            CharlesMaurer

            Thanks but I am still puzzled.  Perform Find [Restore] by itself requires me to specify the date, but I need the user to specify it, so that would not work.  The second suggestion I tried before posting my query, but it finds nothing at all, which I also do not understand.  The third version I shall try but I still do not understand why my simple script does not work, and why the second version does not, and why I would benefit from the added complexity of the third.

             

             

             

             

            • 3. Re: Simple find script doesn't work
              RickWhitelaw

              As Phil explained, your original script is not a "find" script. Entering Find mode does not by itself perform a find.

              • 4. Re: Simple find script doesn't work
                philmodjunk

                The script that you posted and my second example are not the same.

                To use the 3rd and (IMO) better option, you'd put a global field on a layout and enter/select your date in that field before running the script.

                The script would then look like this:

                Enter Find Mode []
                Set Field [YourTable::YourDateFIeld ; YourTable::GlobalDateField]
                Set Error Capture [on]
                Perform Find[]
                If [Not Get ( FoundCount ) // no records found ]
                   Show Custom Dialog ["no records were found"]
                End If

                For more examples of scripts that use this basic pattern see: Scripted Find Examples

                • 5. Re: Simple find script doesn't work
                  CharlesMaurer

                  As I said above, before I posted my query I had already tried Phil's second suggestion.  This found no files whatsoever:

                       Go to Layout [ "chooseDate" )
                       Enter Find Mode [ Pause ]
                       Perform Find []
                       Sort Records [ Restore ; No dialog ]
                       Go to Layout [ "listAppointments" ]
                       Enter Browse Mode []

                  On the other hand, although Enter Find Mode is not supposed to find anything, it does, and the first time it finds the right records.

                  I take your point that I can use a global field but I would like to understand what is going on.

                  • 6. Re: Simple find script doesn't work
                    philmodjunk

                    That's not what you posted originally. A copy/paste from your first post:

                    Go to Layout [ "chooseDate" )
                    Enter Find Mode [ Pause ]
                    Sort Records [ Restore ; No dialog ]
                    Go to Layout [ "listAppointments" ]
                    Enter Browse Mode []

                    Note that Perform Find[] is not there.

                    With the version that you have now posted that does match the second option, there is still no criteria specified for the find. This script pauses in order for the user to enter find criteria. Then they click continue to continue the paused script and find records. So this script will succeed or fail at finding records depending on what criteria is entered by the user during the pause.

                    This is not what I consider to be the best design option for several reasons:

                    1) Using the same fields for data entry and also for searches is dangerous. Users often get confused and try to enter data while in find mode--and then complain that their data disappeared as it was never entered in the first place or enter find criteria while in Browse mode--thus modifying data in unintended ways.

                    2) performing finds other than very simple ones often require a "developer's" understanding of the underlying tables and relationships. The "pause for user input" method leaves it totally up to the user to figure out what criteria to specify in what field in order to find records. A "custom form" used for performing finds can guide the user in their efforts to find records and use value lists or other interface design options specifically designed to help them specify find criteria--thus creating a more user friendly experience. In older versions, I used to set up a custom layout for this purpose and then used New Window to open a modal dialog type window for this purpose. In newer versions, a Popover is a simpler option that works identically on macs and windows systems that can be used for the same purpose.

                    Thus, I typically use the third option with a set of global fields presented to the user in such a "form" for setting up criteria for the find.