Setting up script triggers
You can set up a script trigger to specify that a script runs when an event occurs. For example, you can use a script trigger to run a script that automatically enters data in fields based on what is entered in another field.
Some script triggers run the script before an event is processed by the database engine. Other script triggers run the script after an event is processed by the database engine. For example, you could use the OnObjectEnter script trigger to run a script after a field is entered. (The field is the object; entering the field is the event.)
Script triggers can be activated by user actions or by scripts. For example, you could use the OnObjectEnter script trigger to activate a script to run when a field is entered either by a user clicking it or by a Go to Object script step.
You can set up a script trigger to activate:
-
when a user enters a specific layout. See Setting script triggers for layouts.
-
when a user enters, modifies, or exits an object or objects on a layout. See Setting script triggers for objects.
-
when a file is opened or closed, or the playback state changes for a media file. For information on how to do this, see Setting script triggers for a file.
To see which layout objects and layouts have script triggers assigned to them, in Layout mode, choose View menu > Show > Script Triggers.
The following script triggers are available:
Trigger area | Script trigger | Before processing | After processing |
---|---|---|---|
Object |
|
X |
|
X |
|
||
|
X |
||
X |
|
||
|
X |
||
X |
|
||
X |
|
||
|
X |
||
Layout |
|
X |
|
X |
|
||
X |
|
||
X |
|
||
|
X |
||
X |
|
||
|
X |
||
|
X |
||
X |
|
||
|
X |
||
X |
|
||
|
X |
||
File options |
|
X |
|
X |
|
||
|
X |
||
X |
|
||
|
X |
||
|
X |
Timing of script triggers
When multiple script triggers are activated by the same event, the script triggers perform in the following relative order:
-
OnFirstWindowOpen
-
OnWindowOpen
-
OnLayoutEnter
-
OnModeEnter
-
OnRecordLoad
-
OnLayoutSizeChange
-
OnViewChange
For the following script triggers, the order is controlled by the triggering event:
-
OnObjectEnter
-
OnObjectKeystroke
-
OnLayoutKeystroke
-
OnGestureTap
-
OnObjectAVPlayerChange
-
OnFileAVPlayerChange
-
OnExternalCommandReceived
-
OnPanelSwitch
-
OnObjectModify
-
OnObjectValidate
-
OnObjectSave
-
OnObjectExit
-
OnRecordCommit or OnRecordRevert
-
OnWindowTransaction
-
OnModeExit
-
OnLayoutExit
-
OnWindowClose
-
OnLastWindowClose
Notes
-
Scripts that are run by script triggers use existing privileges. Unless a script is defined to run with full privileges, the script runs using the user's privileges.
-
In Custom Web Publishing and the FileMaker Data API, script triggers can only be activated by a script and not by direct user interaction. Because Custom Web Publishing and the FileMaker Data API don't access data through a FileMaker client's user interface, users cannot activate script triggers directly. But if a script step causes the focus to move into a field, the script trigger will activate.
-
Some script triggers allow for the triggering event to be canceled if the script run by the script trigger returns a False value. When a command or event is canceled this way, the error code is set to 20. See Get(LastError) function for more information. If the script run by the OnLastWindowClose script trigger returns a False value, then the file will not close.
-
Windows: Alt and Ctrl key combinations do not activate script triggers.
-
macOS: Command key combinations do not activate script triggers.