OnWindowTransaction
Performs a script and passes it a JSON object as a script parameter after one or more record changes are successfully committed. The JSON object includes the filename, base table name, record ID, operation, and the contents of a context field for every record operation committed.
Actions that activate this script trigger are:
-
a record is committed after being created, modified, or deleted
-
an open transaction is successfully committed
When the script runs
After the event has been processed.
Modes in which the trigger can be used
Browse and Find modes.
Result
None.
Compatibility
| Product | Supported |
|---|---|
|
FileMaker Pro |
Yes |
|
FileMaker Go |
Yes |
|
FileMaker WebDirect |
Yes |
|
FileMaker Server |
Yes |
|
FileMaker Cloud |
Yes |
|
FileMaker Data API |
Yes |
|
Custom Web Publishing |
Yes |
Originated in version
20.1
Description
Any action that commits one or more records activates this script trigger, whether within an open transaction (see the Open Transaction script step) or not. This trigger passes the script a JSON object as a script parameter containing information about the commits. You can use this trigger with a script that logs every record creation, modification, and deletion—for example, in an audit log of changes, who makes them, and when.
Use the Get(ScriptParameter) function in the triggered script to retrieve the JSON object. The JSON object has the following structure:
{
"FileName" : {
"BaseTableName" : [
[ "Operation", RecordID, FieldContent ],
...
]
}
}
-
"FileName"is the database filename without the file extension. -
"BaseTableName"is the name of the base table for the affected records. -
"Operation"is"New","Modified", or"Deleted". -
RecordIDis the record's internal ID number. -
FieldContentis the content of the context field for that record. You can use this field to pass additional information to the script (for example, the current user, timestamp, and field values). If the field contains valid JSON, it is included as a JSON value rather than as a text string. If no matching context field exists in the table, an empty string is used.
When a commit affects records in multiple base tables, each table has its own array under the "FileName" key. When records in related tables from other files are affected, each file has its own top-level key.
The context field is specified in the Field Name option when configuring this trigger. If Field Name is left blank, the trigger looks for a field named OnWindowTransaction in each base table. If no matching field is found in a table, FieldContent is an empty string for records from that table.
Notes
-
This trigger is configured per file. If records are modified in a related table in another file, those record entries are included in the JSON parameter even if that other file doesn't have the OnWindowTransaction script trigger configured.
-
For deleted records, context field data is captured before the record is deleted. For new and modified records, context field data is captured after the records are committed.
-
Reverted records or transactions don't activate this trigger. See the Revert Record/Request and Revert Transaction script steps.
-
Direct access to the database via FileMaker Data API or OData API doesn't activate this trigger. However, scripts run via those APIs can activate it.
-
For an example audit logging script to use with OnWindowTransaction, see this Claris Engineering Blog post.