5 Replies Latest reply on Jan 31, 2014 7:39 AM by philmodjunk

    Multiple criteria in scripted find

    brianpatterson

      Title

      Multiple criteria in scripted find

      Post

           My Filemaker Pro database has primary and secondary contacts in the contact table, with first name, last name and email in separate fields. I want to allow the user to execute a find script by clicking the enter key on any of these fields. However, the onobjectkeystroke does not activate my script; the built in find behavior prevails.

           Unfortunately, neither my user nor her customers know which of the two contacts is primary and which is secondary. Thus, I must create a search which will take the names (first and last) and search both primary and secondary name fields. I can't find much in the help file on scripted finds.

           I have three questions

           1.     How to I keep filemaker from hijacking my enter key?

           2.     Please give me an idea of how to write the script I need.

           3.     Should I rewrite the table to move contacts to a separate table in accordance with good normalization practices?

            

            

        • 1. Re: Multiple criteria in scripted find
          philmodjunk

               1) Enter layout mode. Select a field and then select the Enter key check box found in the Behavior section of the Inspector's data tab to specify that pressing this key moves you to the next field in the tab order. This will keep pressing the enter key from performing the find and now your script can detect when this key is pressed. But if you use the examples I am about to suggest, you wouldn't necessarily be in find mode in the first place when specifying your find criteria.

               2) See this thread of scripted find examples. Scripted Find Examples The method used in many of these examples is to set up some global fields for entering your criteria while in Browse mode and then the script enters find mode, sets up the search criteria in one or more find requests and performs the find.

               3) hard to say from here, but normalizing your data is most often the best design option unless you have very specific reasons not to.

          • 2. Re: Multiple criteria in scripted find
            brianpatterson

                 I'm still having trouble running a scripted find with multiple criteria, using Perform Find and Extend fund set. If I enter the same criteria and use the menu find, it works. Can anyone offer any additional help.

                  

            #Executed from button on startup layout when user is ready.

            #I don't use menu find because I can't kill off the previous searches.

                  

            #May only be executed from the find screen. Avoid errors from user changing data by mistake

            If[Get(WindowMode ) ≠ 1]

            Show Custom Dialog [ Title: "Procedural error"; Message: "Please return to the main screen and click the 'New Contact Button"; Default Button: “OK”, Commit: “Yes” ]

            Exit Script [ ]

            End If

                  

            #Set gloabal variables gFN1, gLN1, gFN2, gLN2 entered by user

            Perform Script [ “SetContactGlobals” ]

                  

            #Search for name 1 in contact 2 and name 2 in contact 1

            #The database is not normalized. The user doesn't know if the caller is contact 1 or contact 2.

            #There are plans to normalize later.

            Set Field [ CONTACTS::First Name; CONTACTS::gFN2 ]

            Set Field [ CONTACTS::Last Name; CONTACTS::gLN2 ]

            Perform Find [ ]

            Script errors out here - “The provided find criteria is not valid. Enter a valid request before proceeding”

                  

            Set Field [ CONTACTS::First Name 2; CONTACTS::gFN1 ]

            Set Field [ CONTACTS::Last Name 2; CONTACTS::gLN1 ]

            Extend Found Set [ ]

                  

            #Search for name 1 in contact 1 and name 2 in contact 2

            #This leaves the names as entered by the user.

            Set Field [ CONTACTS::First Name; CONTACTS::gFN1 ]

            Set Field [ CONTACTS::Last Name; CONTACTS::gLN1 ]

            Extend Found Set [ ]

                  

            Set Field [ CONTACTS::First Name 2; CONTACTS::gFN2 ]

            Set Field [ CONTACTS::Last Name; CONTACTS::gLN2 ]

            Extend Found Set [ ]

                  

            Further searches for email and phone number ommitted for brevity

            • 3. Re: Multiple criteria in scripted find
              philmodjunk

                   Why does your script insist on Find Mode?

                   The method that I am suggesting does not enter find mode until you get just before the first set field step that specifies find criteria. No special script to set global fields is required and you can't modify the contents of a global field while in find mode. The users would enter their find criteria directly into the globals. This happens to be safer in many ways as it helps keep users from entering find criteria while in Browse mode into the regular fields and then discovers that they modified data instead of specified criteria for a find.

                   That is consistent with your error message as it suggests that you have empty global fields in your first find.

              • 4. Re: Multiple criteria in scripted find
                brianpatterson

                     I am trying to search, edit, find and add new on one layout, so I want the contact identifying fields bound to the contact table. I think it gives a better user experience if information stays in one place on the screen. I suppose I could have two identical layouts, on bound to the contacts names and one bound to the globals. or just give up on my one main interface preference.

                     Half the people around here seem to share about 5 surnames, so I need to have a picklist. I show a calculated field of possible contacts. When the user picks one, the globals are cleared and I use the row position in the found set to move to the same row in the edit boxes. It worked using quickfind, except for quickfind storing and using previous search criteria.

                     How would I load the main working layout from the look-alike find layout, either loading the selected client or setting up for a new client?

                • 5. Re: Multiple criteria in scripted find
                  philmodjunk

                       None of this requires data entry from the user while in find mode. And I suspect that the fact that you are using that approach is why your script didn't work as expected.

                       You would use global fields, either all on one layout (such as in the header) or in a layout that you open in a small floating window. After the user enters data in the global fields while in Browse mode, the script returns to your original layout and performs the find there so there is no separate "find layout", but you might choose to open  small window for gathering find criteria from your user.

                       And you can definitely use value list formats on these global fields to assist the user in specifying find criteria--that's one of the advantages of this method as you can "fine tune" the interface design to better support entry of find criteria--which sometimes benefits from a different value list format than what you'd use for data entry tasks.