1 2 Previous Next 24 Replies Latest reply on Feb 26, 2014 2:57 PM by philmodjunk

    Help with creating a Search Function

    AbdoulBaldé

      Title

      Help with creating a Search Function

      Post

           Hi, 

            

           I am having a hard time trying to create a search function to implement into my solution. 

           Context: This is a visit guide solution. It allows users to create visits by selecting content... and then launch the visit from a library (ortal of all created visits) and view the selected content as well as other infos that are common to every visit. 

           I am trying to create a script that will :

           1- Go to another Layout 

           2- Show All find results (Filepath)

           3- Allow user to go back to the original Layout. 

            

           Could you please help: 

           In the Table from which my Layout is based and where the search is performed, I have created a global field = "search"

           My script is as follows

           Allow user abort (off)

           Set Field [search; ""]

           Perform Quik Find [|

           Find Matching records [Replace;search]

            

        • 1. Re: Help with creating a Search Function
          philmodjunk

               I'm afraid that I don't understand your 3 step script. Show All find results from what find? And what would this have to do with a filepath?

               I suggest that you examine these scripted find examples for ideas: Scripted Find Examples

          • 2. Re: Help with creating a Search Function
            AbdoulBaldé

                 Thanks for the link. It helped me understand better how to enable search using scripts. 

                 Here is where I am stuck. 

                 I would like to add a "g_search" field where user can type in search. (Quick find search).

                 I have created a global field ( Search ) in the table from which my layout is based. 

                 My script is: Allow user abort [Off] 

                 Perform Quick Find [] 

                 My issue is with the "specify" step. Which operator and field do I need to select for the script to work when a word typed in matches the field within whom the search is performed?

                  

                 Thanks. 

                  

                  

                  

            • 3. Re: Help with creating a Search Function
              philmodjunk

                   Quick Find doesn't use operators as I understand it. You can only enter text and then the quick find is performed against all fields on your layout where Quick Find is permitted. I rarely use quick find for that reason. Almost always, the data that is used for my search criteria only makes sense when used as criteria in a specific field and then a normal, scripted find of the type shown in that link does the job for me.

                   In your case, if you are entering data in a global field, your quick find script step can specify the global field in its Specify Calculation dialog and then whatever text was entered into that field is used in the Quick Find as though you had typed it into the Quick Find box in the tool bar.

              • 4. Re: Help with creating a Search Function
                AbdoulBaldé

                     Thanks it works. Although the results are not very precise. If I understand correctly, the other way around is go through a script which would look like this: 

                Enter Find Mode [] ---> clear the pause check box
                Set Field [YourTable::YourField ; Globals::gField]
                Set Error Capture [on] ----> Keeps error dialog from interrupting script when no records are found
                Perform Find []
                If [Not Get ( FoundCount ) // no records were found ]
                    Show Custom Dialog ["No records were found by this search."]
                End IF

                Could you please help me with the specified search criteria for the Perform Find step? 

                     Which field do I select under "Find records when" ?  Is it the field I would like to search within? Which operator will search matches of the words entered? (match whole word)

                     Thanks.

                      

                      

                • 5. Re: Help with creating a Search Function
                  philmodjunk

                       There is no specified criteria in the perform find script. That's why the script shows empty brackets [] instead of [restore].

                       The criteria is specified using set field steps instead. This is both a more flexible way to specify the criteria--you can use a calculation to produce the needed search criteria and it keeps all the criteria immediately visible when you review the script in the script editor (you don't have to open an additional window to review what criteria is specified for the find.)

                  • 6. Re: Help with creating a Search Function
                    AbdoulBaldé

                         Ok I see. Then I don't understand the 

                    Set Field [YourTable::YourField ; Globals::gField]

                    YourTable::YourField refers to the table on which the Layout is based?

                    Globals::gField refers to the field I want to search into?

                          

                    Thanks.

                    • 7. Re: Help with creating a Search Function
                      philmodjunk

                           YourTable would be replaced by the name of the table occurrence on which your layout is based. YourField would be replaced by the name of the field into which you want to enter search criteria. If your layout specifies "Crops" in "show records from" in Layout Setup and the field that you are searching is named "Fruit", then the first part of this set field step would be:

                           Set FIeld [Crops::Fruit ;

                           The expression to the right of the ; semi-colon is what produces the text to be entered as search criteria.

                           Many of the examples in that thread use a field with global storage specified in field options as the source of user entered data to be used to create search criteria. A field with global storage will be accessible from any layout in your file no matter what table it is defined in. I often use a separate table named "Globals" as a way to better keep track of them, but that's merely a preference.

                           So the way this works is that, in browse mode, a user might enter "apple" into the Globals::gField and then performs a script to find all records in Crops where Fruit contains the text "Apple""

                           Set FIeld [Crops::Fruit ; Globals::gField ]

                           would be the script step to produce that criteria in the Fruit field while in Find Mode.

                           The reason that I specify a global field for this is that in find mode, all nonglobal fields appear empty and their data is not accessible. So this type of script has to use data that has been previously entered into either a global field or a variable to be able to use it to create find criteria.

                           If you haven't used set field in a script before please note:

                           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.

                      • 8. Re: Help with creating a Search Function
                        AbdoulBaldé

                             Thanks. I finally got it. Only issue is that the search tool doesn't appear to be very powerful. I have  these words "Place Riopelle"  in the field withing whom I am searching and when entering Riopelle in my search and I have no results.  Search results seem a bit unpredictable. Do you have any tricks to improve the search? 

                             Thanks.

                        • 9. Re: Help with creating a Search Function
                          philmodjunk

                               If you have a text field with the text "Place Riopelle" in it, then using "Riopelle" as your search criteria  for the same field should find that record.

                               If it doesn't, the first thing that I'd check is to see if the text field was really defined as a text field in Manage | Database | Fields.

                               The next thing that I'd check is to see if I'd specified the search criteria correctly.

                          • 10. Re: Help with creating a Search Function
                            AbdoulBaldé

                                 Thanks. A few other questions: 

                                 If search has no results, I would like the user to be directed where he was in the Layout. 

                                 > I have to set a condition If FM error code then (then what? this where I am stuck)

                                 How can I display the results of a search in a portal on my Layout?

                                  

                                 Thanks.

                                  

                                  

                            • 11. Re: Help with creating a Search Function
                              philmodjunk

                                   The search examples use Set Error Capture [on] to keep the "no records found" error message from interrupting the script and presenting the user with options that don't work for this kind of script.

                                   If [ Get ( FoundCount ) = 0 ]

                                   will detect that no records are found and you can put script steps after it to do what you want when no records were found. (show a dialog telling the user no records were found, change layouts, etc.)

                                   

                                        How can I display the results of a search in a portal on my Layout?

                                   Finds don't work that way. They produce a found set, not a group of related records to show in a portal. It can be done, but seems a needless complication. To do it, you have to gather the list of Primary Key values of all your records in the found set into a single text field with returns separating each value and then you can use that text field as the match field for the relationship on which your portal is based--but that's a lot of scripting to do plus (depending on the exact method used and the FileMaker Version that you have) layout design changes when you can just use a list view layout to display the results of your find in the same type of tabular format.

                              • 12. Re: Help with creating a Search Function
                                AbdoulBaldé

                                     Thanks. 

                                     The first part is clear. 

                                      

                                How can I display the results of a search in a portal on my Layout?

                                Finds don't work that way. They produce a found set, not a group of related records to show in a portal. It can be done, but seems a needless complication. To do it, you have to gather the list of Primary Key values of all your records in the found set into a single text field with returns separating each value and then you can use that text field as the match field for the relationship on which your portal is based--but that's a lot of scripting to do plus (depending on the exact method used and the FileMaker Version that you have) layout design changes when you can just use a list view layout to display the results of your find in the same type of tabular format.

                                      

                                I see my question was not clear. I meant How display all search results on my Layout? 

                                Please note this is because the solution will be ran using FileMaker Go only. Therefore there is no Menu bar on top (like in FileMaker Pro) to go to the next record found. 

                                • 13. Re: Help with creating a Search Function
                                  philmodjunk

                                       The search results will automatically be displayed on your layout. If you use a list view or table view, you'll see a tabular format list of the records found and you can add a button to tap that takes you to a layout that shows that record in detail if you want.

                                       

                                  Please note this is because the solution will be ran using FileMaker Go only. Therefore there is no Menu bar on top (like in FileMaker Pro) to go to the next record found.

                                  No, that control will appear in a bar across the bottom of your screen instead when using FM GO. wink

                                       You can also add your own buttons for navigating from record to record if you want to only show one record at a time on your layout.

                                       And in a list view, you can simply use your finger to scroll vertically through the records by dragging up or down on the layout with your finger.

                                  • 14. Re: Help with creating a Search Function
                                    AbdoulBaldé

                                    You can also add your own buttons for navigating from record to record if you want to only show one record at a time on your layout.

                                    How would I do that? My Layout is based on another Table therefore if I use "Go to next record" It will take me to next record from the Layout based table and not the next record of the found set. Could you please advise?

                                          

                                    Thanks.

                                          

                                          

                                    1 2 Previous Next