Brian Dunning's FileMaker Custom Functions

LogFieldModifications ( fieldNameLog ; fieldNameList )

LogFieldModifications ( fieldNameLog ; fieldNameList )

  Be the first to rate this function Log in to vote

Marcus Nilsson   Marcus Nilsson - Show more from this author
Square Moon
https://www.squaremoon.se/

Share on Facebook Share on Twitter

  Sample input:
LogFieldModifications ( fieldName ; fieldNameList )
  Sample output:
{"2021-11-05 13:37:00":{"fieldNameList[1]":"fieldNameListValue[1]"}}

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

/**
* ==================================================================
* LogFieldModifications ( fieldNameLog ; fieldNameList )
*
* PARAMETERS:
* fieldNameLog - log field (auto calc) name
* fieldNameList - list of fields (names) to log
* RETURNS:
* JSON
* EXAMPLE:
* LogFieldModifications ( fieldNameLog ; fieldNameList ) returns {"2021-11-05 13:18:57":{"fieldName":"fieldValue"}} when the record is modified
* DEPENDENCIES:
* None
* AUTHOR:
* Marcus Nilsson, Square Moon, marcus@squaremoon.se
* PURPOSE:
* Log field modifications as JSON in a text field.
* NOTES:
* none
* REVISIONS:
* 2021-11-03 20:52, Marcus Nilsson. Created.
* ==================================================================
*
*/

While (
[
~fieldNameLog = fieldNameLog ;
~fieldLog = If ( IsEmpty ( GetField ( ~fieldNameLog ) ) ; "{}" ; GetField ( ~fieldNameLog ) ) ;

~fieldNameList = fieldNameList ;
~fieldNameCount = ValueCount ( ~fieldNameList ) ;

~currentHostTimestamp = Get ( CurrentHostTimestamp ) ;
~modification = "{}" ;
~i = 0
] ;
~i < ~fieldNameCount ;
[
~i = ~i + 1 ;
~currentField = GetValue ( ~fieldNameList ; ~i ) ;
~modification = JSONSetElement ( ~modification ; ~currentField ; GetField ( ~currentField ) ; JSONString )
] ;
JSONSetElement ( ~fieldLog ; ~currentHostTimestamp ; ~modification ; JSONObject )
)

 

Comments

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: