It may be worth looking at the Audit Trail and Advanced Audit Trail modules. These are used for tracking database changes in a Mendix application. They may do what you need, or they may be something you can extend to meet your needs.
https://docs.mendix.com/appstore/modules/advanced-audit-trail/
https://docs.mendix.com/appstore/modules/audit-trail/
I hope this helps.