14 Replies Latest reply on Oct 18, 2011 9:27 PM by DavidJondreau

    Custom Find mode using scripting

    TonnyOn

      Title

      Custom Find mode using scripting

      Post

      Hello Filemaker pro users,

      I am new to filemaker pro 11, I was hoping if any of you can help me out. I want to use scripting with a custom Find mode with my own dialog box that is able to input a word I type up and once I hit ENTER or "go" it will search the database for matching record/s, if there are no matching record/s it will say fail and have a retry button. Also, Once the record is display, I want to click on that record which will take me to another layout, displaying more info on that specific record.

      Thank you in advance

        • 1. Re: Custom Find mode using scripting
          philmodjunk

          Define a text field, gNameSearch, and give it global storage in Field options.

          You can use either Show Custom Dialog (Simple but limited) or New Window (complex, a bit "clunky", but much more flexible) to open your dialog with this global field as the place to enter the search text. I'll use Show Custom Dialog for this example:

          #Am assuming you are already on the layout where you want to search for records
          Show Custom Dialog ["Please Enter a Name."] //specify gNameSearch as the Input field for this dialog
          Enter Find Mode [] //clear the pause check box
          Set Field [YourTable::TextField ; YourTable::gNameSearch] //this step does not work unless gNameSearch has global storage specified
          Set Error capture [on] //keeps FileMaker Dialog from interrupting script if no records are found.
          Perform Find []
          If [ Get ( FoundSet ) = 0 // no records found.
             Show Custom Dialog ["No records matching " & YourTable::gNameSearch & " were found." ] // Name your buttons Retry, Cancel
             If [ Get ( LastMessageChoice ) = 1 // Retry was clicked]
                Perform Script [//Specify this same script here so that it calls itself]
             End IF
          Else If [Get ( FoundSet ) > 1 // more than one matching record found]
              Go To Layout [Specify a list view layout set up to list your matching record in rows]
              Sort [Restore ; No dialog ] //specify a sort order that organizes the found records in a logical order just as alphabetical order
          End If

          Set up the second layout to list the same name in Show Records FRom in Layout Setup... Arrange narrow rows of data with the fields you want to display data that will help the user deterimine which matching record is the one they really want. Add a button or use button setup to change all these fields into one large button and set the button up to use Go To Layou to return to the layout where you started out to see the "form view" of the selected record.

          If you are interested in the New Window version of this method, let me know. It pops up a window based on a FileMaker layout so you have many more options for setting up multiple global fields with value lists, conditional formatting and  validation rules that you can't do with the simpler show custom dialog option.

          • 2. Re: Custom Find mode using scripting
            TonnyOn

            The problem I am occurring right now is there no error message displaying when I misspell a word or no record/s match and if the dialog box is blank, here is the script I followed:

            Show Custom Dialog ["Please Enter a Name."] 
            Enter Find Mode []
            Set Field [YourTable::TextField ; YourTable::gNameSearch] <--- (For the one highlighted red here, do I need to put in my table TextField field as well or just gNameSearch field)
            Set Error capture [on] 
            Perform Find []
            If [ Get ( FoundCount ) = 0 
               Show Custom Dialog ["No records matching " & YourTable::gNameSearch & " were found." ] <--- I can't perform that 
               If [ Get ( LastMessageChoice ) = 1 
                  Perform Script 
               End IF
            Else If [Get ( FoundCount ) > 1 
                Go To Layout [Specify a list view layout set up to list your matching record in rows]
                Sort [Restore ; No dialog ]
            End If

            Also for the Get function I could only find Get(FoundCount) function

             

             

             

            • 3. Re: Custom Find mode using scripting
              philmodjunk

              If [Get ( FoundCount ) = 0 ]

              Is the part where the script display a custom dialog telling the user that no records were found.

              Set field has two parts in it's parameters. The first is the target field, the part you highlighted in red. the second is the calculation that determines what value is entered into the target field. New users sometimes have problems figuring out how to enter the two parts:

              When Setting up Set Field, there are two Specify buttons that must be clicked. To get Set Field [Table::Field ; Expression], add set field to your script and click the first button (specify target field). Select Table::Field from the list of fields. Do not click the specify button next to the repetition box. Click OK to close this dialog box. Now click the lower specify button (calculated result) and create the expression to the right of the semicolon (;). Do not try to type in the semicolon.

              Throughout this script, you have to use your table and field names in place of mine in order for this to work.

              I'm afraid that "I can't peform that" doesn't tell me enough to identify the problem. Did you try to set this up and get an error message or did you encounter some other problem?

              • 4. Re: Custom Find mode using scripting
                TonnyOn

                Show Custom Dialog ["No records matching " & YourTable::gNameSearch & " were found." ] <--- I can't perform that 

                sorry what I meant to say was this &YourTable::gNameSearch & does not work it will only display &YourTable::gNameSearch

                Set Field [YourTable::TextField ; YourTable::gNameSearch] <--- How can I use to target more than one field using the gName Search

                • 5. Re: Custom Find mode using scripting
                  philmodjunk

                  Seems like you have a quote in the wrong place if you are seeing the literal text &YourTable::gNameSearch, better check what you have entered. I'd guess you you'll find you have this:

                  "No records matching  & YourTable::gNameSearch & " were found."

                  Instead of:

                  "No records matching " & YourTable::gNameSearch & " were found."

                  I'm not sure I understand your qeustion "how can I use set field to target more than one field"? Do you want to enter the same criteria into more than one field or are you having trouble creating the step I've shown here?

                  To enter the same criteria into more than one field, use additional set field steps--each specifying a different field as the target. If you are having trouble creating the set field step, please re-read the 4th paragraph "when setting up set field..." of my last post where I spell this process out step by step.

                  • 6. Re: Custom Find mode using scripting
                    TonnyOn

                    Thanks on the post but I still have problem with set field, this is what I did:

                    Show Custom Dialog ["Please Enter a Name."] 
                    Enter Find Mode []
                    Set Field [YourTable::TextField ; YourTable::gNameSearch] 

                    Set Field [YourTable::TextField2 ; YourTable::gNameSearch]
                    Set Error capture [on] 
                    Perform Find []
                    If [ Get ( FoundCount ) = 0 
                       Show Custom Dialog ["No records matching " & YourTable::gNameSearch & " were found." ] <--- I can't perform that 
                       If [ Get ( LastMessageChoice ) = 1 
                          Perform Script 
                       End IF
                    Else If [Get ( FoundCount ) > 1 
                        Go To Layout
                        show all records
                    End If

                    I want to use find mode to find on more than two different fields the one highlighted in red, I tried to follow your advice but I am not sure 

                    Also I have encounter a problem with the first dialog box, when I click cancel it takes me to a different layout at the else if Function (highlighted at blue), what I want it to do was to stay on the current layout when I click on "cancel" 

                    Once again Phil you are a big help with this

                    • 7. Re: Custom Find mode using scripting
                      philmodjunk

                      What results do you want when you enter your criteria from gNameSearch into these two fields?

                      Do you want all records where TextField and TextField2 contain the text from gNameSearch or do you want all the records where TextField or TextField2 contain the text from gNameSearch?

                      What you have will produce the "and" results. To get an "or" result add a new record/request step between the two set field steps.

                      Also I have encounter a problem with the first dialog box

                      You need to use an If step with get ( LastMessageChoice ) immediately after the show custom dialog so that you can determine which button was clicked. You can then set up and perform the find only if cancel was not clicked to close the dialog.

                      • 8. Re: Custom Find mode using scripting
                        TonnyOn

                        What results do you want when you enter your criteria from gNameSearch into these two fields? 

                        To answer this question, could you show me how to show records where TextField OR TextField2 contain the text from gNameSearch.

                        And for the (LastMessageChoice) if step, do you mean:

                          Show Custom Dialog ["No records matching " & YourTable::gNameSearch & " were found." ] <--- I put the if function here before or after
                           If [ Get ( LastMessageChoice ) = 1 <--- or I put the if step function here 
                              Perform Script 
                           End IF
                        Else If [Get ( FoundCount ) > 1 
                            Go To Layout (
                            show all records
                        End If

                        I still didn't understand, could you show me.

                        • 9. Re: Custom Find mode using scripting
                          philmodjunk

                          Show Custom Dialog ["Please Enter a Name."] 
                          If [ Get ( LastMessageChoice ) = 1 and Not IsEmpty ( YourTable::gnameSearch )]
                             Enter Find Mode []
                             Set Field [YourTable::TextField ; YourTable::gNameSearch]
                             New Record/Request
                             Set Field [YourTable::TextField2 ; YourTable::gNameSearch]

                             Set Error capture [on] 
                             Perform Find []
                             If [ Get ( FoundCount ) = 0 
                                Show Custom Dialog ["No records matching " & YourTable::gNameSearch & " were found." ]
                                If [ Get ( LastMessageChoice ) = 1 
                                   Perform Script [//Perform this script again here]
                                End IF
                             Else If [Get ( FoundCount ) > 1 
                                 Go To Layout [//list view layout used as picklist]
                                 show all records
                             End If
                          End IF

                          I added an extra check in the name search so that no search is performed if the user leaves the input field in the custom dialog empty and then clicks button 1.

                          • 10. Re: Custom Find mode using scripting
                            TonnyOn

                            There seems to be a problem when I enter a record that on find it won't direct me to the new layout page it will just perform the find in the current layout, however, if a similar field has two records that are the same it will direct me to the new layout page

                            What I want was if the record are the same or not it will still go the new layout 

                            if you know how to do it could you please show me

                            • 11. Re: Custom Find mode using scripting
                              philmodjunk

                              From this statement: "Also, Once the record is display, I want to click on that record which will take me to another layout, displaying more info on that specific record."

                              I assumed you wanted to list the found set in a list where clicking a record brought it up in a form view, "detail" layout of the selected record. This result is redundant if you find only one matching record and thus, the script stays on the "detail" layout where I intended this script to perform the find.

                              If you want to see the same layout for all records that are found, we can change the script to be this:

                              Show Custom Dialog ["Please Enter a Name."] 
                              If [ Get ( LastMessageChoice ) = 1 and Not IsEmpty ( YourTable::gnameSearch )]
                                 Enter Find Mode []
                                 Set Field [YourTable::TextField ; YourTable::gNameSearch]
                                 New Record/Request
                                 Set Field [YourTable::TextField2 ; YourTable::gNameSearch]

                                 Set Error capture [on] 
                                 Perform Find []
                                 If [ Get ( FoundCount ) = 0 
                                    Show Custom Dialog ["No records matching " & YourTable::gNameSearch & " were found." ]
                                    If [ Get ( LastMessageChoice ) = 1 
                                       Perform Script [//Perform this script again here]
                                    End IF
                                 Else
                                     Go To Layout [//list view layout used as picklist]
                                     show all records
                                 End If
                              End IF

                              • 12. Re: Custom Find mode using scripting
                                DavidJondreau

                                Once in Find mode, won't that global be unusable? You should set a variable to the global before entering find mode and use that variable.

                                • 13. Re: Custom Find mode using scripting
                                  philmodjunk

                                  The data in all global fields is accessible when in find mode. That's why I specified a global field in the first place. Try it and see! Wink

                                  • 14. Re: Custom Find mode using scripting
                                    DavidJondreau

                                    You're right. My apologies. I was thinking of entering/choosing global data while in Find mode.