9 Replies Latest reply on Jun 22, 2010 4:50 PM by philmodjunk

    Basic Find Script

    David40

      Title

      Basic Find Script

      Post

      I am teaching myself FMP (I am using FMP 9).  I am trying to write a somewhat basic "Find" script.  Right now, I am only able to get all the records in a database.  I would to choose which records to find.  For example, if an address book is my database, I would like to find only those people in a certain zip code.  I cannot find the step that asks for a vale in a data field.

       

      Thank you in advance,

       

      Dave 

        • 1. Re: Basic Find Script
          philmodjunk

          Show Custom Dialog can ask for up to three values--though in many cases it's easier to set up a layout with global fields where the user first enters data, then clicks a button that enters find mode and uses the contents of the global fields to build find requests.

           

          Feel free to post an example of your script so we can help you with it.

          • 2. Re: Basic Find Script
            David40

            I think I may be headed in the right direction, but ...

             

            Not sure where to insert "Show Custom Dialog".  Here is my script:

             

            Go to layout

            Enter find mode

            Set field

            perform find

            Sort records

             

            Dave Forte

            Central Oregon

            • 3. Re: Basic Find Script
              philmodjunk

              That works as long as the fields referred to in Set Field are global fields.

               

              What you've posted is the basic outline for a script that can be made much more sophisticated, depending on your needs.

               

              Here's one basic improvement:

               

              Set Error Capture [on]

              Perform Find []

              Sort Records

               

               

              The set error capture step keeps filemaker from interrupting your script with a "no records match..." dialog box if the user enteres criteria in the global field that don't match any records. You can then use If [ Get (FoundCount) = 0] and Show Custom Dialog to bring up your own message to tell the user that no records were found.

              • 4. Re: Basic Find Script
                David40

                Sorry, but it appears I am missing something.  After inserting the "improvements", I am still getting all the records as an output.

                 

                The "field" in the "set field" is a "number", but "indexed".  

                 

                Dave Forte

                • 5. Re: Basic Find Script
                  philmodjunk

                  The script will work only if the fields where the user entered search criteria are global fields.

                   

                  Let's say your user enters "Apple" in a field and clicks a button to search the database for records where Apple was entered in the Fruit field.

                   

                  You'd put a global field, gFruit on your layout for them to enter the word  apple.

                   

                  Your script would look like this:

                   

                  Enter find mode[] // clear the pause option

                  Set field [Yourtable::Fruit ; YourTable::gFruit]

                  Set Error Capture [on]

                  Perform Find []

                  Sort [No Dialog; Restore]

                   

                  If YourTable::gFruit is not set to have global storage, the script as written, will fail because only global datat fields will retain their data while you are in find mode.

                  • 6. Re: Basic Find Script
                    David40

                    Thank you for your help.  I have sent you a private message so as not to tie up this forum.

                     

                    Dave Forte

                    • 7. Re: Basic Find Script
                      philmodjunk

                      Feel free to keep posting questions! There may be others experiencing the same trouble and who will benefit from the ongoing discussion.

                       

                      Here's a demo file of what I am describing: http://www.4shared.com/file/bb45xfkr/Simple_Find.html

                      Compare it to what you've got and see if you can figure out why it works and what you have does not.

                      • 8. Re: Basic Find Script
                        David40

                        Thank you again for your assistance.  

                         

                        I believe I am venturing into uncharted regions.  Without realizing it, I changed the field value to "Global" and proceeded to lose all the data in that field.  Luckily, it was a practice program so my main dataset was not lost.

                         

                        I believe I need to regroup and approach the problem from a different standpoint.

                         

                        Dave

                        • 9. Re: Basic Find Script
                          philmodjunk

                          Did you down load the demo file?

                           

                          Did it help?