4 Replies Latest reply on May 14, 2011 6:32 AM by LaRetta_1

    Find Script to search from word start only

    AlistairSinclair

      Title

      Find Script to search from word start only

      Post

      Hi,

      I have a textbox using an onModify script trigger, so it searches as you type.

      The find is currently searching for the product, but it searches for anything that has the matching characters, I need it to search from the first character onwards.

      E.g Type in search box "Bla"

      It needs to return the product "Blake Hat Red" but not "Travis Hat Black".

      The search is currently:

      Enter Find Mode []

      Set Field [Products::Name; Products::SearchText]

      Perform Find[]

      I have seen that it may be possible to use some of the operators == * or "" but I'm not sure how to use them.

      Any help would be great thanks.

        • 1. Re: Find Script to search from word start only
          philmodjunk

          I'm wondering if you might be better off to use a filtered portal for this instead of performing a find. What are you trying to accomplish with this combination of script and search field?

          I have a demo file where you can type in text and the portal filter filters the list of portal records to list only the records were the text in a description field starts with the same text that you entered into the search field:

          http://www.4shared.com/file/plr_jbkk/EnhancedValueSelection.html

          The portal at bottom right does the same type of search you describe here.

          • 2. Re: Find Script to search from word start only
            AlistairSinclair

            Thanks for your response, I have a product list I want to narrow down then the user can add items from this list to an order (need this to be "starts with" search).

            I have managed to set this up through a filtered portal using the method you have suggested but the problem is that I am using the file on FMGO and due to the poor refresh rate on the iPad (when I have to refresh the window everytime I enter a character) I was trying to do this in list view instead to see if I could get a better response time.

            • 3. Re: Find Script to search from word start only
              philmodjunk

              Hmmm, the problem is that "starts with" requirement. That's easily handled in the filter expression (which is why I recommended it.)

              Here's an "old school" solution to this problem.

              Define a different calculation field that strips all spaces and other word separators out of your description field:

              Substitute ( DescriptionField ; " " ; "" )

              Perform your find on this field that has turned your text into a single merged word instead of the original description field.

              If you need to eliminate addititional characters, you can include pairs of find/replace strings inside [brackets]. Look up Subsitute in FileMaker help to see the correct syntax for this.

              • 4. Re: Find Script to search from word start only
                LaRetta_1

                'starts with'  isn't difficult in a regular find. Manually you would type ==bla*

                I am not familiar with GO so you'll have to experiment but this script works well in regular files:

                Use this script attached to SearchText (global text) script trigger OnObjectModify:

                Set Error Capture [ On ]
                Set Variable [ $field ; Get ( ActiveFieldName ) ]
                Loop
                Exit Loop If [ Get ( ActiveFieldName )  ≠ $field or IsEmpty ( Products::SearchText ) ]
                Set Variable [ $find ; "==" & Products::SearchText & "*" ] ... see note below
                Perform Find [ Restore ]
                Exit Loop
                Go To Field [ Products::SearchText ]

                Note: here you create the stored find by selecting your Products::Name field and then in criteria just type $find.