Estimated Time To Read This: 3 – 5 minutes
Before FileMaker 10, pretty much the only way to run a script in FileMaker Pro is to click a button (or run it from another script, or from the Scripts menu). There was no way to, for example, run a script when a user makes a change to a field, or to run a script at a certain time, without the use of a plugin. FileMaker 10 introduced the concept of script triggers, which gives developers much more flexibility in using scripts.
There are several ways triggers can be set. Triggers can be set on objects (such as fields, tab controls, portals, etc). This allows developers to run scripts when a user enters a field, or makes a change to the field contents, or even as they type in a field. Triggers can also be set on a layout. This allows a developer to run scripts when a user moves to a new record, when they commit a record, etc. Scripts can also be triggered using the ‘Install on Timer Script’ script step, which will run a script at a specified time interval.
Scripts can be run either before or after the event that triggers them. For example, if a field is set up to have a script that triggers ‘OnObjectKeystoke’, when a user types in the field, the script will be triggered before FileMaker actually enters the character they typed into the field. This allows the developer to cancel the event based on the outcome of the script (using the Exit Script step). If the value in the Exit script step is True, then the event continues (i.e., the character gets entered into the field). If the Exit Script step is false, then the event does not occur (the character is not entered in the field).
For example, a field has a script called ‘Check for T’ attached to a field as an ‘OnObjectKeystroke’ script trigger; the script includes an Exit Script step with the calculation ‘not Get(TriggerKeystroke)=”t”’. When the user types the letter ‘t’ in the field, then the script returns false and the keystroke is ignored (the letter t is not entered in the field).
Examples of Script Triggers
There are too many uses for script triggers to list them all here, but some examples are:
Filtering Data Input – while it has always been possible to validate a field to only contain numeric values for instance, this wouldn’t occur until after the user commits the record, at which point they would have to revert the record or go back and edit the field. By using an OnObjectKeystroke trigger, you can check to see if the user has entered a numeric value as they type. This requires using a new Calculation function called Get ( TriggerKeystroke ). This function captures the key that the user pressed when the script was triggered. You can then build a script that checks if this value is a number, and if not, then exit the script with a value of false. Since the script triggers before the event, returning a value of false will prevent a non-numeric character from being entered.
Switching Layouts (or tabs) based on a value list – by attaching an OnObjectModify script trigger to a field with a drop down list, you can run a script that changes the current layout (or switches to another tab, or similar) when a user selects a certain value.
Filtering a portal or list – attaching a script that commits the current record as an ‘OnObjectKeystroke’ script trigger to a field used to filter a portal allows the user to filter a portal as they type (normally they would need to click out of the field to commit the record). This can also be accomplished in list view by attaching a script that performs a search to a field using ‘OnObjectKeystroke’
Formatting a field – while it was already possible to format a phone number (or postal code, social insurance number, etc) using a custom function as an autoenter calculation, the same function can be used in a script to format the field as the user types (again by using OnObjectKeystroke).





