Script Triggers: Filter as You Type

For years, FileMaker developers have been devising various filter techniques. The idea is that you type all or part of a name, part number, description, etc… and a list of results filters down to show relevant matches. As handy as these techniques are, they always stop just short of perfect because, before FileMaker 10, you had to exit the field before the filter would take effect. Using FileMaker 10’s powerful Script Triggers, you can make the impact of your filtering more immediate.

Note: We’ve never done this before, but the idea, scripts, and sample file for this technique come directly from FileMaker luminary and Six Fried Rice reader David Graham of Bit Tailor. We’re publishing it here (with David’s permission) because it is an excellent example of Script Triggers solving an age-old problem in an elegant way.

There are as many ways to filter lists in FileMaker as there are developers implementing it. The beauty of this technique is that it doesn’t matter if you prefer exploded keys and filtered portals, aggregate text fields and a find, or (my personal favorite) scripted multi-request finds. Whatever you want, when it is fast, clean filtering you’re after, it is always better if the results appear as you type. This sort of thing was essentially impossible with FileMaker 9. Once a user started entering data in a field, you were hands-off until they finished.

Some people dreamed up horrifying solutions with looping scripts and all manner of wackiness. These techniques, in my opinion, never worked well. Consequently, we were always resigned to the “press Enter when you’re done” model. But when the results appear as you type, the user gets immediate feedback, only needs to go as far as necessary to get the result she wants, and doesn’t have to click back into the field to correct or make a change. So it is clearly a better model. See for yourself:

David’s technique relies on the handy OnObjectModify trigger on the filter field to kick off a script every time the field changes. This includes:

You may be tempted to use the OnObjectKeystroke trigger for something like this, but OnObjectModify gets you more bang for the buck: It handles cut and paste, and doesn’t require all the complexity of keystroke triggers.

The Code

I’ll let you explore David’s sample file for the full scoop, but the core of his technique can be found in two places. First, he uses an exploded key filtering technique, which I won’t cover her, except to say that the idea is to process some text data and produce a multi-line key that includes partial match values. In other words, if the value is “Test” then the key would match “T”, “Te”, “Tes” and “Test.” In this way, you can type all-or-part of the value and see the results. Look at David’s ExplodeToMultikey custom function to see how he accomplishes this.

If you prefer, you can use scripted finds and a list view layout to do your filtering instead.

But the interesting part is this very simple trigger script:

Set Variable [$currentObject; Get ( ActiveLayoutObjectName )]
Commit Records/Requests []
Go to Object [ $currentObject ]
Set Selection [ Start: Length (Get(ActiveFieldContents)) + 1]

That’s it. This script really just does two things:

  1. It commits the record, causing anything you’ve typed in the filter field to take effect.
  2. It returns you to the field, so if you type again, your keystrokes will go right on the end of the field.

In this way, as you type, your changes reflect immediately. Very cool.

Note: If you were using finds instead of exploded keys, you would add a a few more steps to your script to switch to Find mode, build a find request or two, and then perform the find.

You can download the working file right here.

Thanks to David for the great technique!

fmCollective, Syndicating The Best FileMaker Blogs

fmCollective has now added syndication and will be bringing fmCollective subscribers the latest and greatest FileMaker blogs from around the world. We are pleased to bring you the excellent writings of Six Fried Rice as our first syndicated feed. More to follow soon, stay tuned.

fmCollective is sponsored by The Proof Group LLC and AdmissionsQuest.com. If you’d like to join fmCollective as a contributing writer, please drop us a note at info@proofgroup.com.

Happy FileMakering

The fmCollective

Using OnModeEnter Script Triggers to Display Custom Find Layouts

Script triggers have in many ways completely changed the game when it comes to Filemaker development.  The fact that I can launch script triggers on mode changes opens up a whole slew of possibilities, one of which is being able to have a huge amount of control over where my users end up and what information they see while they are navigating my system.  If I want to make sure that my users always have fields X, Y and Z regardless of how they get to find mode, I now have a way to make that happen.

The Old Way

Pre-10, it was a little bit of a hassle to try to give users a customized find layout.  For starters, it required scripting a method that would take the user to the correct find layout for their current context, making that process available on the main layout itself via a button and then locking down the permissions and changing the menu commands so that the users could only get to find mode via said button.  It was doable, but kind of a headache.  Now with script triggers, I can simply set a script to run when the user enters find mode that navigates them directly to the custom find layout I’ve built for them, and no matter how they get to find mode they will always end up looking at what I want them too.

How It Works

The process of setting this up is pretty simple in and of itself.  Let’s take a look at our starting point:

A busy browse layout.

There is a pretty good amount of information being laid out for my users on this particular screen.  Really they only ever search in about eight of these fields.  The rest is just clutter when it comes to finds.  So, I want to give them only what they need to see when they run a find.

To do that, I need to take three steps.  The first step is to design my find layout, including only the fields that are essential for my users to find the data they need.  Once I’ve got that done, I need to write a script to navigate to that layout.  This can be a complex navigation script that tracks a history of visited layouts or a simple go to layout script step.  Once I’ve got my script ready, I need to set the correct script trigger to make it run.  The script trigger I’m interested in for this is called OnModeEnter, and you set it on the main detail layout that the users see (the one in the picture above for me).  You can get to the layout script triggers on the last tab on the right in the Layout Setup dialog box.  The OnModeEnter trigger runs whenever the modes you have selected are entered.  So, to make sure that the user ends up on my find layout only when they are entering find mode and not at any other point, I deselect the “Browse” and “Preview” options.  Now, this trigger will only run when the layout I’m on enters find mode, no matter how find mode is entered.  So at this point, when my users try to search for an order they start at the screen above and are immidiately shuttled to the much more find friendly screen below:

Find Mode

Now my users are happy that they have a simple find screen to look at without all the exta clutter, and I no longer have to try to lock down my system of all it’s innate functionality to keep my users where I want them.

Note: There is actually one final note to make all of this work seemlessly.  Since you’ve taken your users away from the main detail page to set the find criteria, you should probably take them back once they actually preform the find.  To do this, you’ll need to write one more script to navigate them back to the main detail page and set it with the OnModeEnter script trigger on the find layout to run when browse mode is entered.  This will make sure that your users are taken back to the details page to view their results.

FileMaker Pro 10: Putting Script Triggers to Work

One of the most exciting new features of FileMaker Pro 10 is Script Triggers, which provides us with a way to handle events. For example, we can automatically run scripts when a user changes to a new layout, when a field's value has been changed, when a record has been committed, and so on.In this article, I'll show you how I am using Script Triggers to log changes to records. This is a fairly

Phoenix FMPug: Presenting FileMaker 10

Just a quick announcement for those of you in the Phoenix area. I’ll be presenting FileMaker Pro 10 with a focus on practical uses for Script Triggers at the next Phoenix FMPug meeting. We’d love to see you there.

Update 10-Jan-2009: I added a link to the RSVP form.

If you plan on attending, please rsvp here so they organizers can get a proper count.

The Phoenix branch of FMPug, the FileMaker Pro Users Group, is young and growing. This meeting promises to be a hit, with all the FileMaker 10 excitement. We’d especially like to thank Audrey Akhavan from FM Magic, Inc, for starting the group and inviting us to present. Thanks, Audrey!

We can’t wait to see you all there.

Now back to regularly scheduled programming.

← Previous PageNext Page →