7 Replies Latest reply on Feb 13, 2013 4:26 PM by philmodjunk

    Need help with a find script

    WendellNeeley

      Title

      Need help with a find script

      Post

           Hi all,

           I need some help with a script that I have put together for my database.  I have a table that is for patients and I want to have a "check" step when adding in new patients to try and prevent double entries (the script is attached to a button).  In doing so, I have chosen to utilize three global fields for the first name, last name and birthdate.  I use these values to input, via a script, into search fields within the table to see if any records exist with those names and birthdate.

           The script is acting in a very unpredictable fashion for me.  Sometimes it will work exactly as intended, and then at other times it will reject a name/birthdate combo that I know is not in the database as already present.  

           Here is the script that I have right now:

           Set Variable [$COUNT; Value:Get (FoundCount)

           Set Error Capture [On]

           Go to Layout ["New Patient Master Layout" (Patient Demographic)]

           Show All Records

           Enter Find Mode []

           Set Field [Patient Demographic::Pt_FName; Patient Demographic::GlobalPatient_FName_search]

           Set Field [Patient Demographic::Pt_LName; Patient Demographic::GlobalPatient_LName_search]

           Set Field [Patient Demographic::Birthdate; Patient Demographic::GlobalPatient_BDay_search]

           Perform Find []

           If [$COUNT > 0]

           Go to Layout ["New Patient Master Layout" (Patient Demographic)]

           Enter Find Mode []

           Set Field [Patient Demographic::Pt_FName; Patient Demographic::GlobalPatient_FName_search]

           Set Field [Patient Demographic::Pt_LName; Patient Demographic::GlobalPatient_LName_search]

           Set Field [Patient Demographic::Birthdate; Patient Demographic::GlobalPatient_BDay_search]

           Perform Find []

           Show Custom Dialog ["There is already a patient with this name and birthdate in the database."]

           Else If [$COUNT = 0]

           Go to Layout ["New Patient Master Layout" (Patient Demographic)]

           New Record/Request

           Set Field [Patient Demographic::Pt_FName; Patient Demographic::GlobalPatient_FName_search]

           Set Field [Patient Demographic::Pt_LName; Patient Demographic::GlobalPatient_LName_search]

           Set Field [Patient Demographic::Birthdate; Patient Demographic::GlobalPatient_BDay_search]

           End If

           Set Field [Patient Demographic::GlobalPatient_BDay_search; ""]

           Set Field [Patient Demographic::GlobalPatient_FName_search; ""]

           Set Field [Patient Demographic::GlobalPatient_LName_search; ""]

           Exit Script

            

           So I don't know if this is even the best strategy for trying to limit double entries, but I have had it work before.  I don't know if I've missed something.

            

            

            

               

        • 1. Re: Need help with a find script
          philmodjunk

               You are counting records before attempting to find records instead of performing the find and then counting records.

               Try your script like this:

               Go to Layout ["New Patient Master Layout" (Patient Demographic)]
               Enter Find Mode []
               Set Field [Patient Demographic::Pt_FName; Patient Demographic::GlobalPatient_FName_search]
               Set Field [Patient Demographic::Pt_LName; Patient Demographic::GlobalPatient_LName_search]
               Set Field [Patient Demographic::Birthdate; Patient Demographic::GlobalPatient_BDay_search]
               Set Error Capture [On]
               Perform Find []
          Set Variable [$COUNT; Value:Get (FoundCount)]
               If [$COUNT > 0]
                   Show Custom Dialog ["There is already a patient with this name and birthdate in the database."]
               Else If [$COUNT = 0]
                   New Record/Request
                   Set Field [Patient Demographic::Pt_FName; Patient Demographic::GlobalPatient_FName_search]
                   Set Field [Patient Demographic::Pt_LName; Patient Demographic::GlobalPatient_LName_search]
                   Set Field [Patient Demographic::Birthdate; Patient Demographic::GlobalPatient_BDay_search]
               End If
               Set Field [Patient Demographic::GlobalPatient_BDay_search; ""]
               Set Field [Patient Demographic::GlobalPatient_FName_search; ""]
               Set Field [Patient Demographic::GlobalPatient_LName_search; ""]
                

               I've also shortened your script by removing steps that were not necessary.

          • 2. Re: Need help with a find script
            WendellNeeley

                 Thanks for catching that.  So the process should be find and then set variable for the FoundCount.  

                 I did end up moving the Error Capture [On] back up to the top as it was messing with the initial find.

                 Again, thank you so, so, so much for the help.  If I could send you a cake, I would :)  

            • 3. Re: Need help with a find script
              philmodjunk

                   "initial find"? there is only one find in the modified script as your original script performed the same find with the same criteria twice producing no change in the records shown in your found set.

              • 4. Re: Need help with a find script
                WendellNeeley

                     I dunno man.  I put everything in exactly as you had it, got a find error notification and then moved the error capture step back up to the top and everything seemed okay.  But I'm pure amateur hour here.  

                • 5. Re: Need help with a find script
                  philmodjunk

                       yes, but what do you mean by "initial find"?

                       What error message did you get?

                  • 6. Re: Need help with a find script
                    WendellNeeley

                         I was getting the usual message that you get when you perform a find and there are no records found.  It's not doing it now, so I don't know the exact wording.  I bet you that I had the Error Capture set below the Set Variable (Count) step accidentally.  It's working like a champ now.  I think we're all good.  

                         Oh, and by "initial find" I meant the one you left in, not the secondary one that I had in the script.  I should have worded that better.  

                    • 7. Re: Need help with a find script
                      philmodjunk

                           There is only one perform find step in the modified version of this script and I placed Set Error Capture immediately before it. The only way that you could get that error message is if your script is not exactly like the one  that I have recommended that you use.

                           Set Error capture is a very good problem solver for keeping certain error dialogs form interrupting your script when your script is set up to handle the error (such as no records found) without needing that message to appear. But set error capture suppresses almost ALL errors that may occur when your script executes. Thus, it is best to not start your script with this step as it can conceal an error condition from you that you need to discover when initially testing a new script.