1 2 Previous Next 22 Replies Latest reply on Oct 21, 2011 6:00 AM by user16037

    Creating "Advanced Search" Layout

    user16037

      Title

      Creating "Advanced Search" Layout

      Post

       Level: Newbie

      I am re-creating an "advanced Search" page for a library catelogue. for example:

      http://www.imarest.org/Knowledge/OnlineLibraryCatalogue.aspx

      I am having trouble with the requirement to make a single text entry field that would search nominated fields depending on the drop down field on the left.

      So, there are a couple of things here: can a field be made to search different field depending on the input of another field?

      Secondly, and this is a concept question, these fields do not need to hold information in a record form there are there just for purposes of enquiry. I have created them but each one is adding another field on every record and this is a database of 53k records so has create a whole lot of nothing which, I assume, reduces the efficiency of the db. Are there temporary fields that can be created for this purpose?

      Thanks for the help. Having read a lot about the system off and online my head is starting to hurt! Touble is I am not too sure how to define the problem to search the forum.

      mat

       

        • 1. Re: Creating "Advanced Search" Layout
          philmodjunk

          can a field be made to search different field depending on the input of another field?

          Are there temporary fields that can be created for this purpose?

          To answer the last question first as we can then build on that in a script example to answer the first question:

          It's often best to define fields with global storage for this purpose. These fields can be defined in a separate table if you wish. I do that for most global fields as it makes it a bit easier to manage them in a complex solution. Global fields can be referenced from any layout in your file without needing a relationship and their contents can be accessed when the layout is in find mode so these two features make them easier to work with in a scripted find like we would use here.

          For Example purposes, let's say you have two fields named "Title" and "Synopsis" and you want to search either or both fields depending on whether the user clicks a check box labeled "title" and/or a check box labeled "Synopsis". You should be able to adapt this concept to work with more and different fields fairly easily.

          On your search form, define two fields and use field options to specify global storage for both: SearchText, SearchFieldsList. I'll assume these are defined in a table named "Globals", but as long as they have global storage, you can define them in any table you want to use for this purpose. Place SearchText on your layout as a simple Edit box. Format SearchFieldsList as field with a check box set. Use "Synopsis" and "Title" as the two values for your value list here.

          Now the script:

          If [valuecount ( Globals::SearchFieldList )]
            Go to Layout [//Specify layout based on your library table where synopsis and title are defined and where you will display the results of the search]
            Enter Find Mode []
            Loop
              Set Variable [$I ; value: $I + 1 ]
              Set Field By Name [ GetValue ( Globals::SearchFieldList ; $I ) ; Globals::SearchText ]
              Exit Loop If [$I = valuecount ( Globals::SearchFieldList ) ]
              New Record/Request
            End Loop
            Set Error capture [on]
            Perform Find []
            If [ Get ( FoundCount ) = 0 // no records found ]
               Go To Layout [original layout]
               Show Custom Dialog [ "No records matching this criteria where found"]
            Else
               sort [no dialog ; Restore ] //sort by title perhaps?
            End If
          Else
            Show Custom dialog ["No field was selected for this search criteria"]
          End If

          Notes: By using New Record/Request while system is in Find Mode, the script creates a second request if both fields are specified for the search. This sets up an OR based search logic where records will be found if the specified text is found in either the title or synopsis fields. Without the new request, the search would be based on AND logic and only records where both synopsis and title fields contained the search text.

          • 2. Re: Creating "Advanced Search" Layout
            user16037

             Dear PhilModJunk,

            Thanks for your answer. I have been going though and trying to deconstruct the steps so that I can understand the process, which has been very helpful.

            I have not as yet got it to work as there is a line that the script editor will not allow me to write:

            " Set Field By Name [ GetValue ( Globals::SearchFieldList ; $I ) ; Globals::SearchText ]"

            the last clause prompts the error "An opertator (e.g. +,-,*,...) is expected here". The rest of the scipt is as you have suggested replacing my fields for yours and changing the layout. Would not being able to insert this section to the step influence the rest of the script?

            Also, and this is a newbieQ, I am applying this script to a "go" button, is this correct?

            Thanks again for your help.

            Mat

            • 3. Re: Creating "Advanced Search" Layout
              user16037

               Apologies, just had another thought. How does the "Globals::SearchFieldList" check box relate to the actual fields? In my scenario they are author and subject and the fields would be "IMarEST test db::author" and "IMarEST test db::subject".

              Thanks again,

              Mat

              • 4. Re: Creating "Advanced Search" Layout
                philmodjunk

                with set field by name, you have two specify buttons at the bottom of the script editor when this step is selected. Click the upper button and enter the expression to the left of the semi-colon. Then click OK, Click the lower button and enter the expression to the left of the semi-colon. Do not enter the semi colon. You'll see it displayed automatically by the script editor once you have entered both parameters.

                Hmm, your last post points out a detail that I had overlooked. To do exactly what my script requires, you'd have two checkbox values in your value list: IMarEST test db::author and IMarEST test db::subject. That's really cryptic to the user. Let's modify that set field by name line to look like this:

                Set Field By Name [ "IMarEST test db""" & GetValue ( Globals::SearchFieldList ; $I ) ; Globals::SearchText ]

                Now your value list can be of just the field names like I originally described.

                • 5. Re: Creating "Advanced Search" Layout
                  user16037

                   Hi there PhilModJunk,

                  There is more... If I understand correctly I am typing in the field names into the value list (I cannot see a way of pointing to the fields themselves) if I chose "use values from field" then I can but that is not what we want.

                  Also another quirk - when I type in your script:

                  Set Field By Name [ "IMarEST test db""" & GetValue ( Globals::SearchFieldList ; $I ) ; Globals::SearchText ]

                  I cannot seem to be able to place the "IMarEST test db""" bit and I get the following in the square parentheses:

                  "IMarEST test db::\"" & GetValue ( global fields table::SearchFieldsList ; $I ) 

                  What am I doing wrong?

                  Thanks for you continued support.

                   

                  Mat

                  • 6. Re: Creating "Advanced Search" Layout
                    philmodjunk

                    Yes, you can't use the specify field option as this lists the values stored in the fields rather than the names of the fields. You'll need to use the custom values option here.

                    My example has an extra set of quotes, must have got a keybounce that I didn't notice.

                    Use:

                     

                    Set Field By Name [ "IMarEST test db" & GetValue ( Globals::SearchFieldList ; $I ) ; Globals::SearchText ]

                    • 7. Re: Creating "Advanced Search" Layout
                      user16037

                       Dear PhilModJunk,

                      I have had some success with the above script.

                      by using the above ammendment to the step I was getting the error "this action cannot be performed because the required table is missing." So I added the double colons and then was only able to search the first criterium, in this case by the "author" field. Removing the ""IMarEST test db" &"  I am able to successfully create "Or" searches in all the fields that I need, as discribed by your first reply. Very pleased, but I am left with the problem of not being able to remove the "IMarEst test db::" from the displayed criteria check box. 

                      kind regards,

                      mat

                      • 8. Re: Creating "Advanced Search" Layout
                        philmodjunk

                        Ok, I should read my stuff more carefully. I got my finger on the " key instead of : when originally typing this expression. You've figured that part out so that the Set field by name works.

                        Are all your fileds defined in the same table (what I assumed) or in more than one table. "IMarEst test db" is the name of a table occurrence in Manage | database | Relationships in your database. If you are searching with criteria in more than one table, then this complicates both the results you may get and this script.

                        Let me know what you have here and we can move forward from there. If the fields are defined in a different table, I will also need to know the relationship between your tables as this can affect the results of your find as well as the function of this script.

                        • 9. Re: Creating "Advanced Search" Layout
                          user16037

                           Dear philModJunk,

                          all the fields are in the same table "IMarEST test db::". this is a stand alone db and I hope to be able to search in four fields:

                          IMarEST test db::author; 'subject; 'title; and 'abstract.

                          cheers,

                          mat

                          • 10. Re: Creating "Advanced Search" Layout
                            philmodjunk

                            Then, (Checking very, very careful for typas, typos....)

                            Set Field by Name [ "IMarEST test db::" & GetValue ( Globals::SearchFieldList ; $I ) ; Globals::SearchText ]

                            Should correctly enter criteria for each selected value in separate find requests.

                            Let's try this experiment. Modify the script like this:

                            If [valuecount ( Globals::SearchFieldList )]
                              Go to Layout [//Specify layout based on your library table where synopsis and title are defined and where you will display the results of the search]
                              Enter Find Mode []
                              Loop
                                Set Variable [$I ; value: $I + 1 ]
                                Set Field by Name [ "IMarEST test db::" & GetValue ( Globals::SearchFieldList ; $I ) ; Globals::SearchText ]
                                Exit Loop If [$I = valuecount ( Globals::SearchFieldList ) ]
                                New Record/Request
                              End Loop
                              Pause/Resume Script [Indefinitely]
                              Set Error capture [on]
                              Perform Find []
                              If [ Get ( FoundCount ) = 0 // no records found ]
                                 Go To Layout [original layout]
                                 Show Custom Dialog [ "No records matching this criteria where found"]
                              Else
                                 sort [no dialog ; Restore ] //sort by title perhaps?
                              End If
                            Else
                              Show Custom dialog ["No field was selected for this search criteria"]
                            End If

                            Make sure the layout selected in line 2 displays each of these fields. Select some values in your check box field and then run the script. The added step will pause just after creating all the needed find requests. If the layout is in form view you can use the book control to click through the requests just like you would records in browse mode. Check and see if the values you selected in the check box each have a find request with that value specified in the correct field. Make sure that the field names in your check box value list exactly match the actual field names deifined. Let me know what you see and we'll go from there.

                            Or, if you have FileMaker Advanced, enable the script debugger and data viewer and run this script watching to see if the values are correctly entered in the correct field in separate requests...

                            • 11. Re: Creating "Advanced Search" Layout
                              user16037

                              LOL! 

                               

                              OK, placed the two global fields in the relavent layout with a button to run the script. On choosing a check box and pressing the button the layout goes into find mode and pauses as we expect and on pressing continue (script paused) it gives the results of choosing the first check box. I have tested the other boxes and the same result occurs. the debugger stalls and points to:

                               Pause/Resume Script [Indefinitely]

                              again, as we would expect.

                              mc

                               

                              • 12. Re: Creating "Advanced Search" Layout
                                user16037

                                 oh and then runs to the end and gives above result without error on the debugger

                                 

                                mc

                                • 13. Re: Creating "Advanced Search" Layout
                                  philmodjunk

                                  The pause won't change the results you get. It's there so you can check on things while the script is paused to see if the correct values were entered in the correct fields as criteria. If you select all three check box values and then run this script, you should be able to run the script and then, while it is paused, flip through what look like three nearly blank "records". These "records" are the requests that Filemaker will use to perform the find. There should be one for each value you selected in the global checkbox field and each should show the same text from the first global field entered into a different field corresponding to the names selected in the checkboxes.

                                  Run the script and check to see what you get. Then let me know what you found as this will tell us where to look more closely at your system to figure out why this isn't working for you.

                                  • 14. Re: Creating "Advanced Search" Layout
                                    user16037

                                     dear PhilModJunk,

                                    OK, in the paused phase of the script (search critrium "Petroleum") having checked all four of the boxes I get six results: 1. petroleum in the name field - this has been deleted from the check box values but used previously; 2. petroleum in author; and four blank records.

                                    I have tried deleting the value list and re-creating it and the results are the same.

                                    mc

                                    1 2 Previous Next