OnWindowTransaction
(OWT) is a file-level script cause introduced in FileMaker 20.1. It turns on every time a transaction is dedicated in a record, offering beneficial features which include creating basic log files and triggering workflow notifications. This trigger is specially useful for troubleshooting records troubles and may be without problems included into current answers.
To permit OWT, go to the File Options dialog, wherein you may set off it like other document-level script triggers. Here, you’ll designate a script to run each time a transaction is devoted—this will be your “Processor” script. Additionally, you need to specify a discipline call, which ought to be introduced to every desk to your answer. The contents of this discipline can be surpassed to the Processor script as a parameter, and I’ll discuss with this discipline as the “Payload.”
With this enabled, any time records are created, modified, or deleted, the Payload data from those transactions will be sent to the Processor script, which can do whatever it wants to with that information, like writing it out to a log file.
About the Payload
The Payload area must be an unstored calculation with the setting “compare usually.” (For further information on how stored and unstored calculations fluctuate on this context, seek advice from my colleague Wim Decorte’s publish.) It is normally defined as a JSON item that consists of applicable information and metadata about the file. Avoid which includes precis fields or unstored calculations inside the JSON, as this could considerably impact overall performance.
For example, in the demo record, the Payload field named “z_wt_Contents” from the Event desk is an example of ways this have to be set up.
And here’s the identically named field from the Registrants table:

Along with the field data, the calculation also incorporates useful metadata, including the AccountName that made the changes, the modification count of the record, and a list of the modified fields. I use underscores in the key names as a straightforward convention to clearly separate data from metadata, which is especially helpful for more detailed loggin
About the Processor
The Processor script you designate may be brought about whenever a transaction is dedicated. This consists of changes made by means of customers, scripted document changes, and bulk operations like imports or update discipline contents. (I won’t delve into the complexities of what constitutes a transaction here, because it’s a vast and nuanced subject matter.)
Here are some key info and concerns for the Processor script:
- Runs at the End of the Script Stack: It executes after all other scripts in the stack.
- Triggered on Any Commit: It activates on every transaction commit.
- May Trigger Multiple Times for Bulk Operations: It might be called multiple times during bulk operations.
- Must Be a Script in the File: The Processor script needs to be in the same file; it cannot be in an external file.
- FileMaker Data API and OData: These do not trigger the OnWindowTransaction event directly, but scripts run via these APIs can.
- Truncate Table: This operation does not trigger the event.
The Processor script can carry out any actions you require. Typically, it must parse the Payload JSON and act upon it, consisting of by way of logging the facts. The Payload may include information about one or more than one facts worried inside the transaction. While you can log the entire payload, it’s far regularly greater effective to parse out and log each report’s movement one after the other. In the demo documents, you’ll locate several Processor scripts to experiment with: the FullPayload script logs the whole payload, the BasicParse script makes a speciality of Delete moves, and the FullAuditLog script statistics all additions, adjustments, and deletions. You can switch between these scripts by means of adjusting the OWT cause settings.
BasicParse and FullAuditLog Scripts
The main task of the BasicParse and FullAuditLog scripts is to traverse JSON nodes to identify individual record changes. You can analyze these changes in two main ways:
- By BaseTable: You would possibly have tables to your answer that don’t require logging, along with utility tables or low-precedence records. I recommend placing a variable within the Processor script with a listing of tables that ought to be logged. The script can then check if the base desk of a record alternate is on this list and bypass it if now not. Filtering in this way—through consisting of tables you want to log in place of aside from the ones you don’t—is usually greater efficient.
- By Action: Each record change in the JSON consists of 3 values: the movement (New, Modified, or Deleted), the RecordID, and the end result from the Payload calculation. The demo document’s script, for example, ignores actions other than deletions since it’s far designed to log handiest deletions.
Logging in a Separate File
It is pretty endorsed to perform logging in a separate record. This technique has several blessings: it maintains your predominant files lean, avoids recursive logging issues (in which logging movements cause the log script), and improves performance by reducing report locks at some stage in busy intervals.
The log document may be sincere. Whenever the Processor script identifies an action to log, it calls a subscript in the Log document to create and populate a brand new document. The Log record also can perform extra JSON parsing if wanted, however be aware about capability overall performance impacts, in particular with excessive person interest. Secondary logging or parsing can be controlled thru separately scheduled batch routines.
Wrapping Up
Implementing a Delete Log in an existing answer is a terrific way to start operating with the OnWindowTransaction cause. This approach is narrowly focused on logging deletions from targeted tables, minimizing overall performance issues and log document size. The accompanying documents are intended for schooling sporting events, so feel free to explore and enhance them as needed.
To study effectively, use the Script Debugger to add, regulate, and delete statistics, staring at the results. Experiment with specific Processor scripts to recognize their variations.
Good luck, and I hope you locate this statistics useful! If you want help, do not hesitate to reach out to our crew of FileMaker experts.