Policy Module Display Data Hook
Overview
The getPolicyModuleDisplayData() hook allows you to customize how policy module data is displayed on the Root management dashboard. This is useful when you need to calculate and display dynamic values (such as the current age of the policyholder), transform stored data into a more user-friendly format, or hide certain internal fields from the dashboard view.
By default, the policy summary screen displays all data stored in the policy.module object. This hook gives you control over what is displayed and how it is formatted, without affecting the underlying data stored on the policy.
The hook is triggered automatically when a policy is viewed on the Root management dashboard, provided both the feature flag and product module setting are enabled.
Enabling the hook
Two configuration steps are required to enable this functionality:
Opt-in
As this is currently a beta feature, you will need to opt in to use this feature. Contact Root support to enable this feature for your organisation.
Product module setting
In your product module's .root-config.json file, you need to enable the override setting:
{
"productModuleName": "Root Funeral",
"productModuleKey": "root_funeral",
"organizationId": "00000000-0000-0000-0000-000000000001",
"host": "http://localhost:4000",
"stack": "root-node-20",
"settings": {
"overridePolicyModuleDataDisplay": true,
...
}
}
If either the feature flag or this setting is not enabled, the dashboard will display the standard policy.module data without any transformation.
Configuring the getPolicyModuleDisplayData() function
getPolicyModuleDisplayData() functionThe function should be defined in your product module code with the following signature:
function getPolicyModuleDisplayData(policy, policyholder, currentUser) {
// Custom logic
return {
display_data: { ... },
module_data: { ... }
};
}
Function parameters
The function accepts three parameters:
policy- The complete policy object, including all standard fields and themoduleobject containing product-specific data.policyholder- The policyholder object associated with the policy.currentUser- Optional. Information about the user currently viewing the policy, including theiruser_id,email, andpermissions.
Return value
The function must return an object with two properties:
display_data- Object. The data that will be displayed on the policy summary screen. This can include calculated fields, formatted values, or a filtered subset of the module data.module_data- Object. The underlying policy module data. This is what will be used to populate any forms that rely on the module data.
{
display_data: {
// Data to be displayed on the dashboard
},
module_data: {
// The underlying module data (typically policy.module)
}
}
Example: Calculating current age
This example shows how to calculate and display the policyholder's current age, even though only their date of birth is stored on the policy.
function getPolicyModuleDisplayData(policy, policyholder, currentUser) {
// Calculate current age from date of birth
const currentAge = policyholder.dateOfBirth
? moment().diff(moment(policyholder.dateOfBirth), "years")
: policy.module.age;
return {
display_data: {
...policy.module,
current_age: currentAge,
source: "getPolicyModuleDisplayData",
},
module_data: policy.module
};
}
In this example:
- The current age is calculated dynamically each time the policy is viewed
- All original module data is included in
display_datavia the spread operator - The
module_datapreserves the original policy module for reference
Example: Filtering sensitive data
This example demonstrates how to hide certain internal fields from the dashboard view.
function getPolicyModuleDisplayData(policy, policyholder, currentUser) {
const { internal_notes, underwriting_score, risk_rating, ...publicData } = policy.module;
return {
display_data: {
...publicData,
cover_amount: policy.module.cover_amount,
monthly_premium: policy.module.monthly_premium,
},
module_data: {
...policy.module,
},
};
}
This approach removes items from the policy display, which do not need to be displayed on the dashboard, while keeping them in the underlying module_data should they need to be referenced in a form or any other dependency.
How the data is displayed
The display_data object returned by your function is rendered on the policy summary screen in a two-column table format. The data is automatically formatted by the Root dashboard:
- Dates: ISO date strings are automatically formatted according to the organization's date format preferences
- Currency: Fields with names containing "premium", "amount", "value", "assured", "income", or "fund" are automatically formatted as currency with the policy's currency symbol
- Booleans:
truedisplays as "Yes",falsedisplays as "No" - Snake case: Field names like
spouse_includedare automatically converted to title case ("Spouse Included") - Nested objects: Object properties are rendered as nested tables for better organization
- Arrays: Arrays can be expanded/collapsed for better readability
You don't need to format these values yourself in the getPolicyModuleDisplayData() function—the platform handles formatting automatically.
Automatic formatting
The Root dashboard automatically formats dates, currency amounts, and other common data types. You only need to return the raw values in your
display_dataobject.
Error handling
The hook includes built-in error handling. If an error is thrown or occurs during execution, the dashboard will:
- Display an error message to the user:
"Error getting policy module data" - Continue to display the rest of the policy information normally
The error will be logged and displayed to the user, but will not prevent the policy page from loading. This ensures that even if the display data calculation fails, users can still access and work with the policy.
Non-destructive display
The
getPolicyModuleDisplayData()hook only affects how data is displayed on the dashboard. The underlying policy data stored inpolicy.moduleremains unchanged and is still accessible via the API.
Updated about 9 hours ago