10 Replies Latest reply on Jun 19, 2012 3:21 PM by StephenWonfor

    Puzzling Two-Step Search




      An odd little puzzle is this: A script that alternates between returning a foundset of 0 and a foundset of "n" records. Fails first time then generally works after that, though for a while it was failing every other attempt.


      The user inputs search parameters into a series of global fields in a "Trainer" table.

      The seach looks into "Certifications" and "Companies" using a trainer_id::trainer_id relationship.

      The search parameters are loaded from global fields into local variables.


      The script logic is like this:


      0. Commit records.

      1. Set local variables from the global fields. No global variables are set oir used.

      2. Test conditions for various search parameters.

      3. Execute the search.

      4. Use the List() function to pull data from the related tables into a variable.

      5. Write the variable into the body of an eMail and send.


      This is OSX 10.7.4 with FMA11 v0.4. Server 11.


      The failure is almost 100% on first try if I close the db and then reconnect. This makes no sense.





      "Egotism, n: Doing the New York Times crossword puzzle with a pen." --- Ambrose Bierce

        • 1. Re: Puzzling Two-Step Search

          Maybe something is global that should be stored and it get cleared when you close the DB. Just a hunch.


          Have you debugged your script?  


          agnes b. riley . filemaker and web development

          FileMaker Business Alliance . FileMaker Technical Network

          www.zerobluetech.com (http://www.zerobluetech.com)



          T 201-299-6223 (NJ) .

          212-842-8830 (NY)






























          917-660-7221 (C)






























          FileMaker Certified in 10 and 11

          people + products + events + todos + invoices + documents = productivity

          • 2. Re: Puzzling Two-Step Search



            Runs well in the debugger but I think there may be something to one of the globals having persistent data in it.  I will examine that - thanks for the pointer.




            "A sure cure for seasickness is to sit under a tree." --- Spike Milligan

            • 3. Re: Puzzling Two-Step Search

              Well.  A quick reveals all the globals open up empty.





              "I sometimes think that God in creating man somewhat overestimated his ability." --- Oscar Wilde

              • 4. Re: Puzzling Two-Step Search
                Stephen Huston

                Are you sure that All Globals are being set correctly before the script progresses? Use the debugger and data viewer to step thru. It sounds like some global is not being correctly set before proceeding.


                Be sure that any global which should be empty is empty, and vice-versa. The script should set every global, even if only to null (using Case tests to determing the correct values), to be sure that session values/globals are not accidentally retained during other searches in the same session.

                • 5. Re: Puzzling Two-Step Search



                  If a global field is created on a server it will always come up empty when the database is opened.  If created in a local copy it will have the last value set when the file is closed.


                  To resolve this I use an on open script to initialize global fields to the desired initial value.



                  • 6. Re: Puzzling Two-Step Search



                    Conditional formatting (Self = "") tells me all the global fields are empty upon db open.  A utility eraser confirms that.  I populate the fields, run the routine, it fails.  I run again - it works.


                    It occurs to me that I could rewrite the whole thing and it would work.


                    "A mistake is simply another way of doing things." --- Katharine Graham

                    • 7. Re: Puzzling Two-Step Search

                      And don't forget that if a scheduled server script sets globals, those will be the default values next time a user opens the file. So yes, having a startup script that sets them the way you want is important.

                      • 8. Re: Puzzling Two-Step Search

                        Are you using after set globals fields and local variables commit?

                        • 9. Re: Puzzling Two-Step Search
                          Stephen Huston

                          It is also good practice to have a script clear global fields/variable at the end of the script if they are no longer to be used. This leaves things nice and clean for using other scripts.


                          There is a real danger that a developer will use a global variable with a name such as $$date or $$total in more than one script, and it's not best practice to leave an old value hanging about that something else might recognize and try to use by accident.

                          • 10. Re: Puzzling Two-Step Search



                            No $$ globals were involve in the production of this script.  All $Globals reset at start of script, then reloaded (even though they shouldn't exist).


                            I rewrote the script - looks and prints exactly the same but works this time.




                            "As a rule, said Holmes, the more bizarre a thing is the less mysterious it proves to be. It is your commonplace, featureless crimes which are really puzzling, just as a commonplace face is the most difficult to identify." --- Arthur Conan Doyle