LogFieldModifications ( fieldNameLog ; fieldNameList )
LogFieldModifications ( fieldNameLog ; fieldNameList )
Be the first to rate this function Log in to vote
Marcus Nilsson - Show more from this author
Square Moon https://www.squaremoon.se/ |
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
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.