KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method to Export Materials for Analyzing Data Changes
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: June 28, 2021

When unrecognized data changes occur in your 4D application, the journal file (.journal) is the best place to review what happened. The method below exports the database's current journal file and structure information into a human readable format for analyzation. The "JournalExport.json" file contains the data modification information present in the current journal file and the "structure_info.xml" file has all the tables/fields details. These files are exported into a newly created folder named "_Analyze_Journal_Materials", located in the database folder. This way, everything needed to analyze the data change is in one folder.

This method can be placed in the "On Backup Startup" method so or called at anytime.

//====================================
//DESCRIPTION: Exports both the journal file and structure information into "_Analyze_Journal_Materials" folder in database folder to analyze changes in the data
//====================================
C_TEXT($savePath; $structurexml; $jsonPath; $text; $jsonString)
C_VARIANT($json)
$savePath:=Get 4D folder(Database folder)+"_Analyze_Journal_Materials:"

//Export structure info and journal file
LOG FILE TO JSON($savePath)
EXPORT STRUCTURE($structurexml)
TEXT TO DOCUMENT($savePath+"structure_info.xml"; $structurexml)

//Pretty Print the json export
$jsonPath:=$savePath+"JournalExport.json"
$text:=Document to text($jsonPath)
$json:=JSON Parse($text)
$jsonString:=JSON Stringify($json; *)
TEXT TO DOCUMENT($jsonPath; $jsonString)