RecordLog ( )

Function stats

Average user rating
5.0000
132
187
9999
Support
FileMaker 7.0 +
Date posted
14 January 2009
Version
1
Recursive function
No

Author Info
 Charlie

7 functions

Average Rating 4.7

author_avatar



 

Function overview

Prototype

RecordLog  ( pLogField;   pChangeList )


Parameters

pLogField  A field in a table used to store the log for that record. This field should be a text field & have the function as the calculated auto enter value.


pChangeList  This should be a list of fieldname:::value pairs


Description

Tags:  record   log   history   audit  

Use this function in a table where you would like to log changes to a records listed fields.

In the example given the field r_log would be in a table used to store the log for that record. This field should ideally have the "Prohibit modification of value during data entry" checked so that the user can't accidentally overwrite the log if it is displayed on a layout such as an "Audit Trail" tab.

The function only tells you that the field has changed & what the new value is. It could easily be modified to show "changed from xxx to yyy".

The data dump under the equals line "===========" is used to determine if any fields passed in pChangeList have changed since the record was last modified.

If multiple fields have changed since the last log the field-value pairs will start on a new line from the timestamp. This will happen when the record is created &/or when fields get added to or removed from the log field autoenter calculation.

Examples

Sample input

RecordLog( r_log ; List(
"Field 1:::" & d_field_1 ;
"Field 2:::" & d_field_2 ;
"Field 3:::" & d_field_3 ;
"Field 4:::" & d_field_4 ;
) )


Sample output

user 13/01/2009 15:06:26 Field 1 changed to 12345
user 13/01/2009 15:06:26 Field 3 changed to abcdef
user 13/01/2009 15:06:26
Field 1 changed to 12345
Field 2 changed to abcdef
Field 3 changed to filemaker
Field 4 changed to test

=========================
Field 1:::12345
Field 2:::abcdef
Field 3:::filemaker
Field 4:::test

 

Function code

Let(
[
_spacer = " " ;
_separator = "¶¶=========================¶" ;
_sepPos = Position( pLogField ; _separator ; 1 ; 1 ) ;
_oldList = Right( pLogField ; Length( pLogField ) - _sepPos + Length( _separator ) ) ;
_change = DiffValues( pChangeList ; _oldList ) ;
_changeList = _separator & pChangeList
] ;

TextColor( Left( Get(AccountName) & _spacer ; 25 ) ; RGB ( 200 ; 200 ; 200 ) ) &
TextColor( Left( Get(CurrentTimeStamp) & _spacer ; 30 ) ; RGB ( 200 ; 200 ; 200 ) ) &

If( ValueCount( _change ) <> 1 ; _changeList ;
Substitute( _change ; ":::" ; TextColor( " changed to " ; RGB( 200 ; 200 ; 200 ) ) ) & ¶ &
Replace( pLogField ; _sepPos ; Length( pLogField ) ; TextColor( _changeList ; RGB ( 200 ; 200 ; 200 ) ) )
)

)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/187

    Prototype: RecordLog( pLogField; pChangeList )
    Function Author: Charlie (http://www.fmfunctions.com/mid/132)
    Last updated: 14 January 2009
    Version: 1

*/
// ===================================