FileMaker 10’s Script Triggers feature opens the door to create richer, more dynamic and more responsive user interfaces. For example, it is now possible to create as-you-type search functionality similar to that found in iTunes and Mac OS X Spotlight where the list of results updates dynamically as the user types. This is a slick feature. I’ve added this functionality to a few of my client’s databases, and it has never failed to elicit a glowing response.
Place a global search field with a script trigger in the header of your list layout for live search-as-you-type functionality
Step One: Create a Global Search Field
This step is the same as Step One in my article, Google-Like Searches In FileMaker. If you have already done this for that project, you can skip this step and use the same field. Otherwise, create a text field in any table. In the field options, set the new field to use global storage as shown in the figure below.

Under the storage tab in the field options, select the "Use global storage (one value for all records)" check box.
Step Two: Create the Triggered Find Script
Create a script that will be triggered when the user enters text. The script will be similar to the one created in the Google-Like Searches In Filemaker - Non Contiguous article except that it will also capture the cursor position within the find field and return it there when complete, and it will not present an error dialog if the found set is empty. Here’s an overview:
- Set variables to store the position of the cursor in the search field and the selection size.
- Enter find mode (do not pause or specify find request).
- Loop through each search term in the global field, create a find request and use the “Set Field” script step to set the find criteria in each field to search. (For more information on understanding this looping process, see Google-Like Searches In Filemaker - Non Contiguous.)
- Perform Find in first loop iteration and Constrain Found Set in subsequent iterations.
- Use the Set Selection script step to place the cursor back in the search field at the position stored at the beginning of the script.
The script will look something like this:
Set Variable [ $selectionSize ; Get ( ActiveSelectionSize ) ]
Set Variable [ $searchList ; Substitute ( g_SearchField ; " " ; ¶ ) ]
Set Variable [ $i ; 1 ]
Loop
Set Variable [ $thisTerm ; GetValue ( $searchList ; $i ) ]
Enter Find Mode [ ]
Set Field [ Contacts::First Name; $thisTerm ]
New Record/Request
Set Field [ Contacts::Last Name; $thisTerm ]
New Record/Request
Set Field [ Contacts::Street Address 1; $thisTerm ]
New Record/Request
Set Field [ Contacts::City 1; $thisTerm ]
New Record/Request
Set Field [ Contacts::State Province 1; $thisTerm ]
New Record/Request
Set Field [ Contacts::Postal Code 1; $thisTerm ]
Set Error Capture [ On ]
If [ $i = 1 ]
Set Error Capture [ Off ]
Set Variable [ $i ; $i + 1 ]
- Add a Freeze Window script step to the beginning of this script and a Refresh Window script to the end. Doing so will help to improve performance and eliminate any possible screen flashes. This is a good general procedure to practice in any of your scripts that change modes, found sets or layouts.
- Use only fields that can be indexed in the search. Avoid related fields or calculations that include them.
Step 3 - Set the Script Trigger
In layout mode, right click on the search field and click “Set Script Triggers …” A dialog will appear:

In the script trigger dialog, select the action (or event) that you want to trigger the script, and select the script to be triggered.
Select the OnObjectModify action which will run the specified script any time text is entered in or deleted from the field. Click Select and choose the script that you created in Step Two.
…And Your Done!
Now the user can simply begin typing in the field and their search results will be refined as they type without requiring that the user enter find mode, know which fields to search or even click a button.
If you have any questions or comments feel free to post a comment below or contact me directly.






12 Comments
Hi Danny
It worked like a charm. Good, simple explanation too. Thanks very much.
Regards
Kevin
Hi Danny,
Works beautifully! Would it be possible to mimic this behavior with a portal? I know about your other articles and have tried them too (and they work too of course).
But this solution has one big advantage: you can type multiple partial words, in any order, to find the relevant records. And I can’t get that working in a portal-type solution.
Thanks & cheers –Mike
For me, it didn’t… I don’t know why, but the Perform Find[] script step just doesn’t seem to do what it should ( and I don’t know why.
And this doesn’t work if the records to be filtered are in a portal. And the similar google like search solutions in a portal, given in the related posts, gives unexpected results when searching for multiple words.
Now I’m frustrated, as I have been trying all day to make this work!
any advice would be appreciated. either post here or email me.
Aaah, I, again, simply used the wrong script step (Perform Find/Replace)
But I am still having trouble since I use a portal: I have to change layout, show all records, loop through all the records to reset a filter field, then do what the article shows, loop through all records in the found set to set the filter field and then come back to layout showing the portal… doing this every time something is typed in the global field takes time.
There must be a simpler way to set such a filter field for all found records at once, no?
Thanks for the comments and positive feedback.
Mike and Denis, here’s a couple of thoughts on using this technique in portals:
Of course, you could combine this technique with the one described in the article, “Google-like Search Through Relationship Filtering,” and the script would only need the first three steps and the final step from the example script in this article. But, as you mentioned Mike, the relationship filtering isn’t as flexible as a find script can be.
One possibility is to use calculated fields in the relationship that splits the words into values on each end (i.e. Substitute ( g_SearchField ; ” ” ; ¶ )).
Another more flexible possibility would be to have a single, global multi-key field that holds a list of primary keys of all of the search results. This would be similar to what you are doing, Denis, except that the script would simply clear that one global field instead of having to show all records to reset a filter field (which will take longer and longer as the database grows). Do the search, then loop through the found records and populate the global multi-key field. To avoid switching layouts which can disrupt the user experience, you could perform the search in a new window that is sized and/or located to be hidden from the user and close that window once the results are processed.
I could probably write another full article on this, but I hope this relatively brief explanation makes sense. Any questions, feel free to post another comments.
BTW: Denis, you are not alone. Using the Perform Find/Replace where you really need Perform Find script step is an extraordinarily common error.
Thanks for the tip. Used
if ($selectionStart=1)
show all records
end if
after Set Variable ($selectionStart……)
to show all records on full delete of search terms?
Seems neater to me.
@chris - thanks for the idea. The only problem is that the user could end up at position 1 without clearing the contents of the field. If they simply deleted the first character in the search field, all the records would be shown.
Alternatively, instead of “if($selectionStart=1)”, you could do “if(isempty(g_SearchField)))” to get the desired result. Move that block to the beginning of the script and possibly add an “Exit Script” after Show All Records since it won’t be necessary to continue the script (or put the rest of the script in an “else” block).
This is great but it does not seem to work with fields that contain numbers. I have to put an * in the field and it is still quirky. Had anyone else ran accross this? Is there an easy solution?
Thanks,
Steve (A FileMaker Newbie!)
Hello,
I’m new to filemaker. I tried the script above and got it to work, almost. Every time I type a letter in the search field, the script pauses. I even tried putting freeze window at the beginning. Any idea what I could do to fix this?
found my mistake!
I had Enter Find Mode [pause] instead of Enter Find Mode [ ]. I have another problem now though. As I enter the letters, the cursor stays at the front of the edit box, so the word gets entered in backwards. Any thoughts?
@Ronald - Check the first and last steps of your script. It sounds like it is not properly capturing and returning the cursor position. The first step in my example above is grabbing the cursor position within the field. The script then leaves the field and in the last step returns to the global field and restores the cursor to its previous position.
Hi Danny!
You script works like a charm! Thanks for the post!
I tried to follow your explanation regarding the portal adaptation but I’m not sure what to do. How should I populate the global multi-key field?
Thanks!