EnxDataRetention
Overview
Seamlessly implement secure, compliant, and easy-to-manage data retention in your Mendix applications.
Documentation
Purpose
The EnxDataRetention module helps Mendix developers securely and easily implement automated data retention policies, ensuring compliance with standards like NIS2, while maintaining an excellent developer experience.It provides an intuitive way for business users and developers to collaborate on defining retention rules, making secure data lifecycle management understandable and easy to implement without excuses.
Installation
Dependencies
Before installing, ensure the following dependencies are in place:
-
MxModelReflection module: Needed to configure modules/entities with a RetentionDate attribute.
-
ComboBox widget
-
DataWidgets.Export_to_Excel
Steps
-
Security: Assign the appropriate user roles to manage rules.
-
Navigation: Add the rule management page to your app’s navigation.
-
Layout: Adjust or configure a layout for the rule management screens if you are not using the Enexis theme
-
AfterStartup Actions:
-
Add USE_ME/ASU_ValidateAllRules to the AfterStartup microflow to validate all rules on every startup.
-
Optionally, add a MxModelReflection sync to AfterStartup to capture any model changes.
-
-
Entity Preparation:
-
Add a RetentionDate (DateTime) attribute to every entity that needs data retention.
-
Add an index on the RetentionDate attribute (consider composite indices with the trigger attribute for best performance).
-
-
Cascading Deletes:
-
The module leverages cascading deletes in Mendix to automatically delete related data.
-
Ensure that RetentionDate is set only on the main object (the parent entity).
-
Configure cascading delete behavior correctly in the domain model for associated child objects. This ensures complete cleanup without leaving orphaned data behind.
-
-
Administration Setup:
-
Add the USE_ME/Rule_Management_Overview page to your app's administration section.
-
Assign administration permission (typically to a technical admin role, like Technisch beheer).
-
-
Layout Adjustments:
-
If not using the Enexis theme, fix two layout errors by assigning your preferred layouts to the rule management pages.
-
-
Scheduled Event:
-
During deployment, configure and enable the Scheduled Event to run the retention processes (default schedule: daily at 03:00 AM UTC).
-
-
Configuration in MxModelReflection:
-
After deployment, in MxModelReflection, set the checkbox on modules containing entities with a RetentionDate attribute.
-
-
Rule Configuration:
-
Create and configure data retention rules via the administration page.
-
Make sure to also create a deletion rule job.
-
Configuration
-
Configuraion tab: Limit Default: 500.Defines the batch size for processing records to avoid table locks and allow efficient batch processing. Jobs are resilient to server restarts and errors.
-
Configuration tab: Fiscal yearDefault: 01-01.Defines the month and day of the start of the fiscal year. Is used when calculation retention period based on fiscal year.
-
Constant RetentionDateAttributeNameDefault: RetentionDate.Allows you to define a different attribute name. You can list multiple attribute names separated by commas; the system will use the first matching attribute that is a non-virtual DateTime.
Functional Details
Retention Calculation
-
Calculation always starts at the beginning of the day.
-
The base date can be:
-
A given date (for date-based triggers. A date attribute in the record).
-
The current date (for value-based triggers).
-
-
Time periods supported: Day, Month, Year, Fiscal Year.
Technical Implementation
Cascading Deletes
The EnxDataRetention module automatically supports cascading deletes and domain model before delete events.When a main object is deleted based on its RetentionDate, all related objects configured with Delete behavior in the domain model are also deleted and the before (or after) delete handler is also triggered.
Important guidelines:
-
Always set the RetentionDate and business rule on the main object only (parent entity).
-
Ensure delete behavior is correctly configured for child objects in the domain model.
-
Review associations carefully to avoid accidental retention of orphaned data.
Job Queries
-
Clear Job
-
Criteria:
-
RetentionDate IS NOT NULL AND DateAttribute IS NULL or
-
RetentionDate IS NOT NULL AND ValueAttribute != value.
-
-
Action: Empties the RetentionDate.
-
Benefit: No need for OFFSET, job can resume smoothly after restarts.
-
-
Set Job
-
Criteria:
-
RetentionDate IS NULL AND DateAttribute IS NOT NULL or
-
RetentionDate IS NULL AND ValueAttribute = value.
-
-
Action: Sets the RetentionDate.
-
Benefit: No need for OFFSET, job can resume smoothly after restarts.
-
-
Delete Job
-
Criterium:
-
RetentionDate is in the past.
-
-
Action: Deletes the data (and cascades deletes to related objects).
-
Benefit: No need for OFFSET, deletion continues even after interrupts.
-
Indexing Recommendations
-
For Clear and Delete:Use an index on (RetentionDate, TriggerAttribute) for optimal performance.
-
For Set:Best index is (TriggerAttribute, RetentionDate).