Disclaimer: I used ChatGPT while investigating the issue. Eventually, it prepared the summary I'm publishing below
I’m trying to create a report in EspoCRM (using the Advanced Pack) that lists Accounts with at least one active Contact. In this context, "active" refers to a Contact with the relationship field isInactive set to false. This isInactive field is stored in the intermediary table account_contact, which holds additional attributes for the many-to-many relationship between Account and Contact (specifically, role and isInactive).
Report Configuration:
Observed Issue:
When I save or run the report, I get an Error 500 with the message Invalid column name. The EspoCRM system log provides further details, showing:
Troubleshooting Steps:
Assumption: It appears that EspoCRM’s reporting system may not natively support filtering on fields stored in many-to-many intermediary tables, such as account_contact. While I can display and manage isInactive through the standard UI (e.g., in detail views of Account or Contact), attempting to filter by it in reports causes an SQL error.
Workaround Attempted: I created a calculated boolean field (hasActiveContacts) in the Account entity using a formula to check for any related Contact with isInactive=false. This approach provides an indirect way to filter accounts based on active contacts, which I can then use in the report filter. While this works, it feels like a workaround, as it requires creating additional fields and recalculations.
Question: Is there a way to directly filter on many-to-many relationship fields (like isInactive in account_contact) in EspoCRM reports? If not, are there any recommended approaches or planned updates to support this kind of reporting natively?
Additional Notes: I want to avoid modifying core files or custom-coding extensively to maintain update compatibility.
I’m trying to create a report in EspoCRM (using the Advanced Pack) that lists Accounts with at least one active Contact. In this context, "active" refers to a Contact with the relationship field isInactive set to false. This isInactive field is stored in the intermediary table account_contact, which holds additional attributes for the many-to-many relationship between Account and Contact (specifically, role and isInactive).
Report Configuration:
- Entity Type: Account
- Filter: Contacts.Account Inactive == No (selected directly from the filter list in the report configuration)
Observed Issue:
When I save or run the report, I get an Error 500 with the message Invalid column name. The EspoCRM system log provides further details, showing:
Code:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'contacts.account_is_inactive' in 'where clause'
- Database Check: The account_contact table indeed has role and is_inactive columns, with is_inactive being set to 0 or 1 for active or inactive contacts, respectively.
- Custom Configuration: The Contact.json metadata in the core application defines the accounts field with "columns": { "role": "contactRole", "isInactive": "contactIsInactive" }, making these fields available in the relationship context.
- Testing Without Filter: The report works fine without the Contacts.Account Inactive filter, suggesting the issue specifically arises from attempting to filter on this relationship field.
Assumption: It appears that EspoCRM’s reporting system may not natively support filtering on fields stored in many-to-many intermediary tables, such as account_contact. While I can display and manage isInactive through the standard UI (e.g., in detail views of Account or Contact), attempting to filter by it in reports causes an SQL error.
Workaround Attempted: I created a calculated boolean field (hasActiveContacts) in the Account entity using a formula to check for any related Contact with isInactive=false. This approach provides an indirect way to filter accounts based on active contacts, which I can then use in the report filter. While this works, it feels like a workaround, as it requires creating additional fields and recalculations.
Question: Is there a way to directly filter on many-to-many relationship fields (like isInactive in account_contact) in EspoCRM reports? If not, are there any recommended approaches or planned updates to support this kind of reporting natively?
Additional Notes: I want to avoid modifying core files or custom-coding extensively to maintain update compatibility.
Comment