Creating and managing layouts and reports > Setting up script triggers
 

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 file options.

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

OnObjectEnter

X

OnObjectKeystroke

X

 

OnObjectModify

X

OnObjectValidate

X

 

OnObjectSave

 

X

OnObjectExit

X

OnPanelSwitch

X

 

OnObjectAVPlayerChange

 

X

Layout

OnRecordLoad

X

OnRecordCommit

X

OnRecordRevert

X

 

OnLayoutKeystroke

X

 

OnLayoutEnter

X

OnLayoutExit

X

 

OnLayoutSizeChange

 

X

OnModeEnter

 

X

OnModeExit

X

 

OnViewChange

 

X

OnGestureTap

X

 

OnExternalCommandReceived

 

X

File options

OnFirstWindowOpen

 

X

OnLastWindowClose

X

 

OnWindowOpen

 

X

OnWindowClose

X

 

OnFileAVPlayerChange

 

X

Timing of script triggers

When multiple script triggers are activated by the same event, the script triggers perform in the following relative order:

1. OnFirstWindowOpen

2. OnWindowOpen

3. OnLayoutEnter

4. OnModeEnter

5. OnRecordLoad

6. OnLayoutSizeChange

7. OnViewChange

For the following script triggers, the order is controlled by the triggering event:

1. OnObjectEnter

2. OnObjectKeystroke

3. OnLayoutKeystroke

4. OnGestureTap

5. OnObjectAVPlayerChange

6. OnFileAVPlayerChange

7. OnExternalCommandReceived

8. OnPanelSwitch

9. OnObjectModify

10. OnObjectValidate

11. OnObjectSave

12. OnObjectExit

13. OnRecordCommit or OnRecordRevert

14. OnModeExit

15. OnLayoutExit

16. OnWindowClose

17. 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 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.

Related topics 

Debugging scripts

Using the Data Viewer

Install OnTimer Script script step