In my v8 version instance, there is an error logged when I open a contact detail view. No error is on the UI but in the log file (suitecrm.log).
SELECT emails.`date_sent_received` FROM notes
LEFT JOIN contacts contacts ON notes.contact_id=contacts.id AND contacts.deleted=0 AND contacts.deleted=0
LEFT JOIN users jt1 ON notes.assigned_user_id=jt1.id AND jt1.deleted=0 AND jt1.deleted=0
INNER JOIN contacts notes_rel ON notes.contact_id=notes_rel.id AND notes_rel.deleted=0
where ( notes.contact_id='768607bc-83ad-11ef-8040-78726430b17c') AND notes.deleted=0
ORDER BY emails.`date_sent_received` DESC LIMIT 1
MySQL error 1054: Unknown column āemails.date_sent_receivedā in āfield listā. Has anyone faced the same issue in version 8. Thanks!
1 Like
pgr
6 October 2024 15:02
2
That āFROMā is clearly wrong. It seems to be a part of the ContactsLastTouchPoint statistic⦠but I donāt know why itās brokenā¦
1 Like
Itās in 8.7 fresh installation.
rsp
7 October 2024 14:56
4
Harshad:
``date_sent_received
Maybe you donāt need those quotes. Check where is code for it.
Hi,
The issues seems to be in subpanel definition in Notes Module. Can you please check subpanel definition file
modules/Notes/metadata/subpanels/ForHistory.php
. The Query has no join to EMAILS table and the select statement and order by statement is referring to a column belonging to emails table.
The issue is fixed by changing the indexes of $queries in ContactLastTouchPoint in 8.7 similar to 8.6.2.
$parts = $queries[5];
.....
$parts = $queries[6];
There were indexes difference in this file in 8.6.2 and 8.7 . The $queries list has different indexes 8.7 and 8.6.2 in ContactLastTouchPoint.php but the order of subpanels in subpaneldefs.php in two versions is not different.
8.7
Core\core\modules\Contacts\Statistics\ContactLastTouchPoint.php
$queries[4] & $queries[5]
$parts = $queries[4];
$parts['select'] = 'SELECT emails.`date_sent_received` ';
$parts['order_by'] = ' ORDER BY emails.`date_sent_received` DESC LIMIT 1';
$innerQuery = $this->joinQueryParts($parts);
$emailsResult1 = $this->fetchRow($innerQuery);
$parts = $queries[5];
$parts['select'] = 'SELECT emails.`date_sent_received` as `emails_date_sent` ';
$parts['order_by'] = ' ORDER BY `emails_date_sent` DESC LIMIT 1';
$innerQuery = $this->joinQueryParts($parts);
$emailsResult2 = $this->fetchRow($innerQuery);
8.6.2
core\modules\Contacts\Statistics\ContactLastTouchPoint.php
$queries[5] & $queries[6]
$parts = $queries[5];
$parts['select'] = 'SELECT emails.`date_sent_received` ';
$parts['order_by'] = ' ORDER BY emails.`date_sent_received` DESC LIMIT 1';
$innerQuery = $this->joinQueryParts($parts);
$emailsResult1 = $this->fetchRow($innerQuery);
$parts = $queries[6];
$parts['select'] = 'SELECT emails.`date_sent_received` as `emails_date_sent` ';
$parts['order_by'] = ' ORDER BY `emails_date_sent` DESC LIMIT 1';
$innerQuery = $this->joinQueryParts($parts);
$emailsResult2 = $this->fetchRow($innerQuery);
1 Like
pgr
13 October 2024 21:00
7
Nice detective work!
Can you open a PR on Github with this fix?
Thanks. It looks this change was made for fixing a bug in 8.7. Raised a new issue for this.
pgr
31 January 2025 15:17
9
That would be this issue, I believe
opened 04:44PM - 14 Oct 24 UTC
Type: Bug
Priority:Important
Severity: Moderate
### Issue
There is a fatal error reported in the log file from the 8.7 version.⦠The error is not displayed on the UI but reported in the log file.
Error:
```
SubpanelCustomQueryPort: Error executing custom query Query Failed: SELECT emails.`date_sent_received` FROM notes LEFT JOIN contacts contacts ON notes.contact_id=contacts.id AND contacts.deleted=0
AND contacts.deleted=0 LEFT JOIN users jt1 ON notes.assigned_user_id=jt1.id AND jt1.deleted=0
AND jt1.deleted=0 INNER JOIN contacts notes_rel ON notes.contact_id=notes_rel.id AND notes_rel.deleted=0
where ( notes.contact_id='257653c8-87fa-11ef-8040-78726430b17c') AND notes.deleted=0 ORDER BY emails.`date_sent_received` DESC LIMIT 1: MySQL error 1054: Unknown column 'emails.date_sent_received' in 'field list'
```
It looks the indexes are changed and so this might be breaking the query for subpanels in Contacts module.
Path:
**Core\core\modules\Contacts\Statistics\ContactLastTouchPoint.php**
$queries[4] & $queries[5]
There are indexes difference in this file in 8.6.2 and 8.7. The $queries list has different indexes 8.7 and 8.6.2 in ContactLastTouchPoint.php but the order of subpanels in subpaneldefs.php in two versions is not different.
Changing the indexes of $queries in ContactLastTouchPoint in 8.7 similar to 8.6.2 fixed the issue in my suite8.7 installation.
changed the above indexes as $queries[5] & $queries[6] in 8.7 in the same file.
I am not sure if this is the correct fix, or I am missing something.
### Possible Fix
Reverting the indexes $queries array order $queries[4] & $queries[5] by $queries[5] & $queries[6] reectively.
in Core\core\modules\Contacts\Statistics\ContactLastTouchPoint.php
### Steps to Reproduce the Issue
```bash
1. Log into the suite 8.7
2. Click on 'Contacts' module menu
3. Open a contact detail view
4. Check for the error in suitecrm.log file
...
```
### Context
_No response_
### Version
8.7
### What browser are you currently using?
Chrome
### Browser Version
_No response_
### Environment Information
MariaDB, PHP 8.2
### Operating System and Version
Windows
and it should be fixed in v8.8
1 Like