Components Crossplatform Mac & Win Server Client Old Deprecated Guides Examples Videos
New in version: 9.2 9.3 9.4 9.5 10.0 10.1 10.2 10.3 10.4 10.5 Statistic FMM Blog
Log record change.
|Component||Version||macOS||Windows||Server||FileMaker Cloud||FileMaker iOS SDK|
|timestamp||Pass here the timestamp field you added for auditing to the table.||AuditTimeStamp|
|TableName||The name of the table.
With 10.2 optionally as second value the name of the audit log table unless you take the default AuditLog.
|FieldsToIgnore||A list of field names to ignore. Global fields and those set with Audit.SetIgnoredFieldNames are always ignored.||"myField"||Optional|
DescriptionLog record change.
In order to setup this for a table, please add two fields to the table. First a field called AuditTimeStamp which is of type timestamp. In the options enable in the Auto-Enter tab the option to set a new timestamp on modification. Next create a new field AuditState and make it a calculated value with the calculation MBS( "Audit.Changed"; AuditTimeStamp; TableName ). The Field "AuditTimeStamp" can be renamed to something like "sAuditTS" but has to be correctly referred to and should be included in the "Audit.SetIgnoredFieldNames" call if changed. By passing here an auto entered modification timestamp you make sure the plugin is informed about all changes to this table. Please uncheck the checkbox for "Do not replace existing value of field (if any)".
For logging you need a table named AuditLog with a few fields. Required are fields named FieldName, FieldHash, TableName, RecordID. Optionally you can add more fields: FieldValue, FieldOldValue, FieldType, UserName, IP, CurrentTimestamp, TimeStamp, CurrentTime, CurrentDate, Action, CurrentHostTimeStamp, PrivilegeSetName, AccountName, LayoutNumber, ApplicationVersion, FileName, HostApplicationVersion, HostName, HostIPAddress, LayoutName, PageNumber, LayoutTableName, TableID, FieldID, CurrentTimeUTCMilliseconds, ScriptName and WindowName.
The plugin will fill those fields with values evaluated from Get() function. FieldOldValue is only filled if we find an older log entry for the field based on the hash. With 4.2 plugin you can also use field Platform to know if plugin was executed on server or client.
You can get access of a record logged if you use a script tigger to set the AuditTimeStamp field with a new timestamp whenever a record is loaded.
This functions work even with separated files where data and layouts are in separated database files. The AuditLog table can be in a separated file as long as the plugin can can find a table occurence named "AuditLog", referencing to the original table which may be located in another FileMaker file and a layout based on this table occurence, named "AuditLog", to write into the log.
The two fields AuditTimeStamp and AuditState can have different names. In that case we recommend to call Audit.SetIgnoredFieldNames in order to have the plugin ignore those fields. Or pass the field names to this function.
To get all your existing records introduced to this Audit Function, move over all records in a loop in a script and call Audit.Changed to log the current one. This helps to fill the FieldOldValue field.
And finally if you like, you can even built yourself an undo mechanism by restoring changes.
On FileMaker 10 the Audit functions only work if tables and base tables have same name. Also we can't record FieldID or TableID on FileMaker 10. For FileMaker 11 and 12 everything works nice.
In the fields to ignore parameters you can pass extra values "FieldName|Value" to assign special values automatically to your fields. As this parameter can be build with a calculation, you can query variables or other tables for information you want to log. With plugin version 7.2 and newer this works for number fields in addition to text fields.
Table names are case sensitive. If you change case of a table name, the fields may be logged again.
With plugin version 4.4 you can use * on the end of the name to match all names starting with same text.
Indexes in the AuditLog table help to speedup the queries internally made by plugin. Especially indexes for the fields FieldHash, FieldName, RecordID and TableName.
Version 8.5 can use either FieldName or FieldID in AuditLog table to identify the field. For the value we prefer to use FieldHash, but if you have no such field, we use FieldValue. AuditLog field list is now queried via SQL instead of using a layout. So with version 8.5 the AuditLog layout is optional.
If there is a failure in the generated SQL, you may see it with FM.ExecuteSQL.LastErrorMessage and FM.ExecuteSQL.LastSQL functions. The audit functions relay on the permissions to make SQL queries on your tables.
Log record on changes:
Log record on changes except fields fullname and zipCity:
Log change and pass value for custom log field "InsideScript" with value of variable:
Log changes and pass custom GUID field while also checking a global variable to disable auditing for batch imports:
Run Audit.Changed with list of fields in a global field in the table:
Run Audit with GetFieldName with v8.3 or newer:
Run Audit with Perform Script on server for FileMaker Go:
- MBS FileMaker Plugin, version 10.4pr5
- Perform Script on Server with Audit for FileMaker Go
- MBS FileMaker Plugin, version 10.4pr2
- MBS FileMaker Plugin, version 10.4pr1
- MBS FileMaker Plugin, version 10.2pr2
- MBS FileMaker Plugin, version 10.1pr4
- MBS FileMaker Plugin, version 8.5pr5
- Audit with MBS FileMaker Plugin
- Audit with MBS Plugin and FileMaker Server, works with FileMaker go!
- Audit Tip for Importing
- Version 10.4
- Fixed a crash in Audit functions when querying GetFieldID internally. Affects Audit.Backup, Audit.Backup2, Audit.Changed, Audit.Changed2, Audit.Delete and Audit.Delete2 functions.
- Fixed an issue where Audit.Changed would rebuild the table cache too often.
- Improved Audit.Changed and related to only query table list once per call.
- Version 10.2
- Version 10.1
- Changed Audit.Changed and related to work with PageNumber and LayoutNumber as numeric fields.
- Version 8.5
- Improved Audit.Changed and related to set last error for SQL calls.
Created 18th August 2014, last changed 7th October 2020
Feedback: Report problem or ask question.
MBS Xojo Plugins